C# browser automation that will work on server - c#

I have been using WatiN for some browser automation and website testing. Recently I received a request to automate some task that needs to check a partner website for existence of some SKU (since they don't have a proper API) and confirm transaction.
I tried using WatiN, but since this runs on a server and on-demand, the server desktop is naturally locked at most times and the IE window does not open and the process is never run.
I am looking for an alternative to WatiN, which is preferably a .net library (not a must, but just makes things easier), does not require a logged in user and being free and open source is always nice.
Anyone have experience with this type of automation?

You can use the Selenium WebDriver coupled with PhantomJS.
Selenium is similar in many ways to WaitN but it supports more browsers. PhantomJS is a headless browser and wrapped in a portable executable you can run from your web server.
Once you've added the NuGet packages, you will be able to instantiate a PhantomJS web driver and control a site without having to launch a full-fledged browser.
var driver = OpenQA.Selenium.PhantomJS.PhantomJSDriver();
We use this on build servers since the build agents are not logged in and won't be able to launch a normal browser process.
If you just need to check some HTML, you can use WebClient to make a request to the site, return the content response as a string and parse it.

Related

WebBrowser not executing Google Analytics Javascript

I have a website running locally and I want to test the GA code I have by hitting the website repeatedly (with a delay) using C#'s WebBrowser class. The issue is that the GA code (the event) is sent with $('document').ready() and I cannot for the life of me get WebBrowser to actually load the javascript on the page.
I was able to get this to work by using Chrome or Firefox by using var proc = new Process("firefox.exe", "my-ga-args") and that works, but I'd like to run this in the background while I'm doing other work and even if I modify the process to start minimized it still takes focus away from my main window when it closes and re-opens Firefox (using different GA parameters that I have in a list that its looping through).
So, is there any way to get WebBrowser to actually execute javascript that exists on the webpage and have it hidden from view while running?
I think you're looking for something like Google's Puppeteer or given your C# tag, perhaps the .NET port Puppeteer Sharp.
... library which provides a high-level API to control Chrome or Chromium over the DevTools Protocol. Puppeteer runs headless by default, but can be configured to run full (non-headless) Chrome or Chromium.

How to open a webpage on a local computer outside of its hosted RDP connection?

I would like to know if there is a technique or solution for the follow problem.
I have a software application that is currently running inside of a Microsoft RDP session. I have some help resources built into it in which some of them open up on a webbrowser. Some of them are YouTube videos. The problem is taht through organisational policies, they cannot open YouTube clips within the RDP which connects to a interstate server.
What I would like to do is instead open up a webpage outside of that RDP connection on the local host computer instead, which does not have any restrictions like opening up YouTube webpage to play video clips.
Can you please suggest a technique, utility or solution to this problem?
Thanks,
Colin.
The nicest way to do this would probably be to create a dynamic virtual channel plugin for RDP: https://msdn.microsoft.com/en-us/library/bb540859(v=vs.85).aspx
You would have a server-side component registered to handle the protocols (http/https, I assume) you want to redirect back to the client, possibly with some filtering logic if you still want a few to run server-side (such as intranet sites); then a client-side mstsc plugin whose only job is to call ShellExecute on the URLs you pass back.
Piggybacking on clipboard redirection might be less code, but it obviously has side-effects - e.g it obliterates anything else the user might have had on the clipboard.

WPF Window is not Opening from IIS [duplicate]

I want to run an exe on client system from my c# asp.net website. When I use Process.Start()
it throws an error:
The requested operation requires elevation.
How do I set permissions to run that exe?
You can't spawn processes on the client machine from server-side code.
When you use Process.Start in server-side code, it is attempting to execute the process there, on the server where the website is hosted. If you wanted to create processes on the clients computer then you would need to expose a download for them (and not in employing subterfuge, like malign sites might do to install software - supply it gracefully, and normally (and with permission)), or a Silverlight application or something along those lines.
The bottom line is that the code you want to execute (even if that is just to spawn a process) must reside on the client, and be executed there.
You can't run an application from a web server like that. You will have to have the user download the application by supplying the EXE, a setup file or using ClickOnce.
Or you can develop an ActiveX control that you can have the browser automatically download from a Trusted Internet Zone.
Once downloaded, proper signing with a certificate (signed from the trusted (corporate) root certificate) will avoid the user getting a prompt to ask whether he wishes to allow the ActiveX control to install/be activated -
The ActiveX control can subsequently do anything the interactively logged on user could. This means that to actually install a program you'd need to elevate (UAC on Vista+); But if the goal was just to run a standalone executable, you should be good to go.
This all assumes white-hat purposes in a (larger) corporate setting, because it relies on PKI infrastructure and central browser policies, to name just two.**
This would, really, lead to some excellent questions on serverfault or superuser
I noticed you said you wanted to run an exe file on the client, but you didn't say explicitly that the exe is on the server and you want to push it to the client. Everyone seems to be assuming that is the case.
You CAN accomplish this fairly easily with a small JavaScript if you have a few prerequisites:
The executable is already present on the client machine.
All of your clients are running IE
You can enforce a policy to put your site in the Intranet or Trusted
Sites zone.
So basically this means it's a corporate intranet application. I am assuming this is probably the case since, well, if you were expecting to do this with a public app, I would be surprised.
For the script to accomplish this, please see my answer to this question:
How can I get a program on a client machine to run from an ASP.NET page?

automated task with selenium on a website

I have an application that is accessed by many users. It's a .net 4.0 C# web forms application, and they requested me to automate a task that they have to do almost daily. The task I should automate is to access a link outside my domain and fill it up with some info, log-in, and other stuff like dates.
So, after many researching and reading, I've managed to do it locally with Selenium. I have the entire process automated and I call it from a link inside my website. Locally it works like a charm.
Here's the code:
public void AutomateTask()
{
var url = new Uri("http://127.0.0.1:4545/wd/hub");
var capability = DesiredCapabilities.Chrome();
var driver = new RemoteWebDriver(url, capability);
driver.Navigate().GoToUrl("url");
//do all the stuff I need to do
driver.Close();
}
I start my server using this command:
java -jar C:\...\selenium-server-standalone-2.43.1.jar -role hub -port 4545
The main problem is that I have to publish my website for the users and they should be able to use the automated process without having to start a selenium node on their machines or anything else. Locally I have a node running for each browser, is it possible for them to consume this webdrivers? I mean, users should not worry about installing or anything, they should just click the link and see their browsers acting till the task is over. When I click at the link on my application(from my local IIS) on another computer, a new window of the request browser is opened on server machine, not on the machine which clicked the link.
I've looking everywhere for a solution for this but none was found.
So:
I have a website that access a third website.
I need to automate this process.
Users must only click the link, wait the new browser window open, wait for some fields to be filled automatic and then fill the captcha and press "continue", then enjoy their browser working.
Is it possible with selenium? If not, which framework or how can I achieve this?
Let me know if any further details are required.
If you don't need to show the browser to the users you could just put a link on your webapp which runs selenium on the machine hosting your webapp. That way you only need to have selenium installed and running on the webserver hosting your webapp and not all the end user machines. If you do it this way you should probably use the HtmlUnitDriver because its headless and you really aren't going to be watching these selenium tests executing.

How to start up your .NET program from web browser?

Could you provide example of JavaScript function for starting up application installed on your computer from a web browser (eg google chrome 4). It particular if .Net APPs have any special simplifying this process apis of out there are some libs for such staff, please share link with us.
so how to create and store in run on start up programs a small local server which would handel some local urls like http://localhost/maAppServer/MyAppCalculator/Start for starting apps that have written in its config file their names and local urls on install?
So how to start up your C# .NET app\program from web browser?
I don't believe its possible in Chrome, starting an EXE on a users computer could be considered a security violation. Some ActiveX, and file:// links in internet explorer may work. Also, OneClick deployment may do something similar to what you are after (not exactly though I don't think, and I believe they require an add-in which may not be available for Crhome) http://www.15seconds.com/issue/041229.htm
I'm not sure what you're asking for. You can start an application on your computer just by linking to it in the HTML page. However, if you need to pass data to it, then it's a different matter altogether, although it's still simple.
An example is what www.nexon.com does with it's MMORPG, MapleStory. You log on to the website, and the web page starts the game after the authentication. Another example would be the magnet links on file-sharing sites.
You need to create a protocol handler, it can be in any language like C++/C# and register it on the client's computer. Like so - http://msdn.microsoft.com/en-us/library/aa767914(VS.85).aspx
Then, just use the protocol you built to pass on whatever data necessary. You can add a link that can be clicked, a button, Response.Redirect() from the server, whatever you like.

Categories

Resources