Using headless browser in Coypu - c#

I've heen recently using Coypu (https://github.com/featurist/coypu) for some web pages automation and it's great for that, if you need UI. But I wonder if I could do it on a headless browser, afaik Copyu supports only GUI browsers out of the box and I dont see any options to set headless mode.
Is it possible with default browsers or should I add some by myself (for example PhantomJS), and how could I do that?

Related

Keep selenium out of focus for user

I am using selenium in C#. I am curious if there is a way I can make it so that as a user you can still do what it is you are doing without being interrupted by selenium. For example, if I am typing something and selenium opens a new tab, my mouse focuses on the tab it opened and doesn't allow me to type unless I click on where I am typing again. Would this be something to do in code or in windows settings?
Run browser in headless mode , in this case the browser runs without GUI so there won't be any interruption
All browsers support headless flag now , add headless argument to capabilities while creating the browser instance
Previously headless browsers like phantomjs used to use webkit rendering engine but now chrome has inbuild headless support and uses same rendering enginee blink
so there is no effect of quality
You can run in headless mode.
Basically in headless mode as name sounds, there's no windows. You do not even need browser in your system.
Code:
var chromeOptions = new ChromeOptions();
chromeOptions.AddArgument("--headless");
chromeOptions.addArguments("window-size=1920,1080");

How can I run a selenium script in the background or minimize mode?

I am writing a script in Selenium WebDriver using C#. I want to run this script in the background or minimize mode. I don't want to display the browser to the user. I tried the Chrome Options class and its properties to accomplish the task but unable to do that.
What could be the best approach of running the selenium script in the
background or minimize mode in Selenium WebDriver using C#?
To minimize:
driver.Manage().Window.Size = new Size(-2000, 0);
To background use a headless webdriver:
WebDriver htmlUnitDriver = new HtmlUnitDriver();
Or for Headless Chrome, see here, it's not a simple solution though.
Best approach: depends on your case. For testing a web app use Chrome minimized. For scraping, use a headless browser.

Can you change IE document mode using Selenium WebDriver and C#?

I'm using WebDriver and Selenium Server 2.28. I'm running this on a Windows 7 environment, and the version of IE is 9.0.8.
I'd like to know if there is any way of forcing compatibility mode in IE using Selenium 2. I've googled this, and there doesn't seem to be a lot of information about this.
How about changing the properties and forcing IE to open in Compatibility mode until you are finished testing? You'll need to run as Admin.
Without further details it is hard to give specific details, but you can force IE into a specific compatibility mode using a special <meta> tag:
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
A value of EmulateIE7 will tell IE to evaluate the <!doctype> as if it'd be IE7. Other valid values would be IE7, IE8, IE9, or Edge, which will use the specific version's behavior.
Just keep in mind that the differences implied by this aren't necessarily 100% the same as when using the specific browser versions (but it should be very close especially regarding JavaScript/DOM and HTML).

Create a Chrome instance in WatiN

I have been using WatiN with IE with great success, however am now wanting to move onto Chrome. It seems to me that if I can just create an instance of a Chrome browser it should be a similar process, but creating an instance of Chrome is proving to be a tricky task.
I am currently looking at:
WatiN.Core.Native.Chrome.ChromeBrowser
Am I on the right track? Or am I missing assemblies for a WatiN.Core.Chrome?
EDIT:
I have now investigated Selenium and am using it with some success for Chrome, Firefox and IE. For those requiring multiple browser support I would suggest Selenium over WatiN, at least till they have finalised their Firefox and Chrome implementations. Both are very handy for UI testing in general though!
Official website states that only supported browsers are IE 6-9 and FF 2-3. Chrome browser is only in experimental mode and isn't yet supported. There are couple of so posts stating that there was no success using chrome in Watin.

interacting with the browser using C#

i wish to interact with my browser window may be IE great if it works on Firefox too, using C#.
I want to make a software which can fill the entries in a webform automatically. In old times there was gator now is roboform, where it can fill in the values automatically.
I actually have users who are comfortable working on an old windows forms application, so i want to make a solution where they can still enter the data in their windows application and it actually fills in the entries at the web form and acts as if the request had generated from the browser itself.
I know i can merge both the databases, since it is a legacy application re writing the database for windows app is a trouble..
Any suggestion?
WatiN is designed to make testing web applications easy from .NET, and it sounds like it could be handy for what you want to do:
Following is the Hello world example
of web test automation; searching
Google.
[Test] public void
SearchForWatiNOnGoogle() { using (IE
ie = new IE("http://www.google.com"))
{
ie.TextField(Find.ByName("q")).TypeText("WatiN");
ie.Button(Find.ByName("btnG")).Click();
Assert.IsTrue(ie.ContainsText("WatiN"));
} }
WatiN Feature List
Automates all major HTML elements
Find elements by multiple attributes
Supports AJAX website testing
Supports frames (cross domain) and iframes
Supports popup dialogs like alert, confirm, login etc..
Supports HTML dialogs (modal and modeless)
Works with Internet Explorer 6, 7, 8 and FireFox 2 and 3
It's billed as a testing application, but Selenium RC can be used to fill in forms and is fairly easy to setup. You could also check out WatiN. Don't know anything about what security issues you might see though.
You might also want to check out Selenium which is a web application testing framework that you can programmitically interact the web UI.
If you use fiddler you may be able to see what the browser sends back to the server, and so you could write C# code to generate the same kind of HTTP request.
If the interaction is very complex (it often is with modern webapps), you could instead automate the browser, as you suggested.
I've had some success automating IE by using the InternetExplorer.Application object. It basically launches a copy of IE and lets you control it from code. I wrote a script this way a few years ago to search for cheap train ticket reservations for me on the Virgin Trains website.
The problem was that with some IE installs, it would sometimes stop to give security warnings that I couldn't skip automatically. There didn't seem to be a pattern to this.
If your users are simply using the application via a WindForms application, then is there any particular reason why you have to manipulate the user interface of an existing web browser, such as Internet Explorer, rather than just making the necessary HTTP requests yourself in your WinForms application? You can use the WebRequest class by setting the Method property to "POST" and writing the field data to the Stream, which you can get using the httpRequest.GetRequestStream() method.

Categories