Controlling Opera Driver from within .NET - c#

How can I control Opera Driver https://github.com/operasoftware/operadriver/ (or even Opera the browser itself) on Windows from within the .NET framework?
My goal is to make something similar to Browsershots.org

The easiest way to do this would be to use the RemoteWebDriver, which requires the Selenium server to be running. The code would look something like the following (Warning: untested code).
// Assumes the Selenium server is running on port 4444 on localhost.
// Note that the Opera() method of the DesiredCapabilities class is
// not included in 2.0rc2 (the currently available binary release),
// but does exist in the trunk.
IWebDriver driver = new RemoteWebDriver("http://localhost:4444/wd/hub", DesiredCapabilities.Opera());

Related

Selenium - start your normal chrome and not chromium

im looking example how can i start my normal google chrome in webdriver c#?
For now i use :
ChromeDriver driver;
public ChromeDriverService chromeDriverService;
chromeDriverService = ChromeDriverService.CreateDefaultService();
chromeDriverService.HideCommandPromptWindow = true;
var chromeOptions = new ChromeOptions();
chromeOptions.AddArguments("disable-infobars");
chromeOptions.AddExcludedArgument("enable-automation");
chromeOptions.AddAdditionalCapability("useAutomationExtension", false);
driver = new ChromeDriver(chromeDriverService,chromeOptions);
But it run my chromedriver.exe installed inside project. Can i just run my simple installed chrome? Without download any chromedriver.exe? It's important for me , because some website check if there is opened chromium with chromedriver.exe.
Is it possible to do that?
If you want not just open it but also perform some interaction with your site then you have to deal with Selenium and WebDriver.
You can try Python and undetected-chromedriver which has some workarounds preventing some systems to detect that your browser is running under webdriver control.
Unfortunately, it's the chromedriver.exe that lets you interact with Chrome so, without the driver, you wouldn't be able to interact with the actual browser.
If your issue is with chromium, try driving Mozilla with GeckoDriver
Selenium always uses chromedriver.exe for interacting with Chrome, I think you mean you want to load your default data directory. You can add a chrome option for this purpose:
chromeOptions.AddArguments(#"C:\Users\<your user name>\AppData\Local\Google\Chrome\User Data")
Take care, any other chrome must not be running that time with the same data directory. Like you may have run for your personal use.
You can also create a data directory somewhere else if you just want to show some realistic behavior to a website. But some websites are smart enough so it does not work every time.

Geckodriver 0.16.0 start firefox with flashplayer

Since geckodriver v0.16.0 flashplayer is disabled by default.
Is there any possibility to start firefox with enabled flashplayer?
I'm using C#. My code right now:
var profileManager = new FirefoxProfileManager();
FirefoxProfile profile = profileManager.GetProfile("selenium"); //created firefox user named selenium
profile.SetPreference("plugin.state.flash", 1);
Code bellow doesn't work for me:
profile.SetPreference("dom.ipc.plugins.enabled.libflashplayer.so", true);
When I use this one:
profile.SetPreference("plugin.state.flash", 1);
firefox is asking if I want to enable flashplayer, and than refreshes page (with all inputs filled previously - so i got empty fields).
If I select "allow and remember", next time I start this code nothig is saved. I'm getting the same situation.
I found solution there:
How to enable Adobe Flash in FireFox Selenium webdriver with FirefoxProfile
If I replaced profile.setPreference("plugin.state.flash", 1); to profile.setPreference("plugin.state.flash", 2); it stopped to asking me if I want to enable flash player.
Here is the solution for you:
With Selenium 4.3.0, gecko driver v0.16.0 & Mozilla Firefox 53.0 this code works well with myfreecams.com.
It is worth mentioning that the default Firefox profile is not very automation friendly. When you want to run automation reliably on a Firefox browser it is advisable to make a separate profile. Automation profile should be light to load and have special proxy and other settings to run good test. You should be consistent with the profile you use on all development and test execution machines. If you used different profiles everywhere, the SSL certificates you accepted or the plug-ins you installed would be different and that would make the tests behave differently on the machines.
So, Create a New Firefox profile and use the same in the Test script involves three steps process. First you need to Start the Profile Manager, second is to Create a New Profile and third is to use the same profile in Test scripts. Let's assume we created a new FirefoxProfile by the name "debanjan".
Use the following code to open http://www.myfreecams.com/ with your new FirefoxProfile "debanjan":
String driverPath = "C:\\Utility\\BrowserDrivers\\";
//Mozila Firefox
System.setProperty("webdriver.gecko.driver", driverPath+"geckodriver.exe");
ProfilesIni profile = new ProfilesIni();
FirefoxProfile testprofile = profile.getProfile("debanjan");
DesiredCapabilities dc = DesiredCapabilities.firefox();
dc.setCapability(FirefoxDriver.PROFILE, testprofile);
FirefoxDriver driver = new FirefoxDriver(dc);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
driver.navigate().to("http://www.myfreecams.com/");
PS: This code is in Java so you may have to convert it into C# format.
Let me know, if this helps you.

NTLM authentication in Selenium RemoteWebDriver

I am trying to use the Selenium HtmlUnit driver in C# tests. As far as I know, the only way to use the HtmlUnit driver in C# is through Selenium server and the RemoteWebDriver:
var driver = new OpenQA.Selenium.Remote.RemoteWebDriver(
OpenQA.Selenium.Remote.DesiredCapabilities.HtmlUnitWithJavaScript());
However, I also need to use NTLM authentication. Using the non-remote driver in Java, it can apparently be configured like this:
WebDriver driver = new HtmlUnitDriver() {
protected WebClient modifyWebClient(WebClient client) {
// Does nothing here to be overridden.
DefaultCredentialsProvider creds = new DefaultCredentialsProvider();
creds.addNTLMCredentials("userName", "password", null, -1, "myComputerName", "myDomain");
client.setCredentialsProvider(creds);
return client;
}
}
(Source: https://groups.google.com/forum/#!topic/webdriver/ktIWIs5m0mQ)
But this obviously does not solve my problem since I am using C#. How can I do that ? (I can use Chrome successfully, but I would like to use HtmlUnit for speed).
Thanks !
In order to pass credentials you need to overload the modifyWebClient of the HtmlUnitDriver, as you saw in the discussion link1.
For the .NET developer the only way to use the HtmlUnitDriver is via the RemoteWebDriver, and based on the discussion HtmlUnit wrapper for .NET2 the developers chose not to expose all of the HtmlUnit driver classes:
I'm loathe to take any more dependencies in the .NET
bindings... If you're dead-set on using HtmlUnit as your headless browser of choice, you can always use it via the RemoteWebDriver
Therefore you cannot use NTLM, or any other credential method, with the RemoteWebDriver.
If you were willing to do and maintain the work you could convert all the HtmlUnit code as detailed in the second link of #JasonPlutext's answer3.
The original sample appears to be from the selenium FAQ.
Linked to from Is there an HtmlUnitDriver for .NET? here on SO.

What is my next step after Selenium grid hub & nodes have been set up?

I have a Selenium Grid hub version 2.22.0 set up with 5 nodes running. Here the list of them:
1 Local node running windows 7(my machine)
1 Virtual machine running Windows XP
1 Virtual machine running Windows Vista
2 Virtual machines running Windows 7
I want to be able to send jobs to those machines that will load a specific browser(s) and use webdriver to drive commands through them.
I need to do It using Visual Studio with C# language.
(Also, I booted the grid and all of the nodes using Java standalone servers, does that mean my webdriver will need to be written in Java also?)
If you know of any current tutorials using webdriver and grid that would be great. (all the tutorials I can find use selenium grid version 1)
Those are Java specific commands are to initiate Grid and register the Nodes. It has nothing to do with Scripts.
You can write scripts in your preferred Language (C#,Java..etc).
Here are some pages which gives more information on how to write Selenium code in C# and how to use Grid.
http://www.theautomatedtester.co.uk/tutorials/selenium/selenium_two_csharp_nunit.htm
http://code.google.com/p/selenium/wiki/Grid2
I hope this helps you ...All the best :)
When you start your nodes you give them something like
-browser "-browserName=internetexplorer,version=9,platform=windows"
When you write your tests you can use this node with the following code:
String gridconfig = "your grid url";
DesiredCapabilities capabilities = new DesiredCapabilities("internetexplorer", "9", Platform.WINDOWS);
RemoteWebDriver driver = new RemoteWebDriver(new URL(this.gridconfig), capabilities);
//Do your test stuff with driver

C# OpenQA and OperaDriver() problem. No Opera at selenium OpenQA v2.5

I am trying to use OperaDriver for selenium.
IWebDriver wd = new OperaDriver();
but using OpenQA.Selenium.Opera; does not exist. I can not find it in C# dll. I am using v2.5 drivers. Chroom, Ie, Firefox exist but no Opera. Where can i get it?
There is no native OperaDriver in the .NET bindings. Opera decided to implement their driver in Java, and not to implement the RemoteWebDriver JSON wire protocol. As such the only way to use the Opera driver from .NET is to use the .NET RemoteWebDriver class, along with an instance of the standalone Java Selenium server, which is available on the project downloads page.
Assuming you are on Windows:
The Operadriver is written in Java and not suported directly in C#, as it is mainatined not by the Selenium project team but by Opera.
To use it, you have to run the standalone Selenium webserver (from console on windows) before starting the test. get it here
you need to set the OPERA_PATH to point to your opera.exe file. Start the server with the command:
java -jar selenium-server-standalone-2.33.0.jar
i use a small bat for these two tasks:
SET OPERA_PATH="C:\Progra~2\Opera\opera.exe"
cd C:\pathToSeleniumJarFile
C:\Progra~2\Java\jre7\bin\java.exe -jar selenium-server-standalone-2.33.0.jar
C#:
testing with remotewebdriver object in your C# code to connect to it.
switch (WebBrowser)
{
case Browser.Chrome:
// chromedriver.exe has to be in the debug folder
ChromeOptions chrome = new ChromeOptions();
chrome.AddArguments("--ignore-certificate-errors");
webDriver = new ChromeDriver(chrome);
break;
...
case Browser.Opera:
//note: set OPERA_PATH environment variable (in cmd or global)
DesiredCapabilities opera = DesiredCapabilities.Opera();
opera.SetCapability("opera.profile", #"C:\OperaProfile");
webDriver = new RemoteWebDriver(opera);
break;
default:
throw new NotImplementedException();
if you want to manipulate the profile of the opera client (e.g. to accept untrusted certificates etc) you need to set
opera.SetCapability("opera.profile", #"C:\OperaProfile");
Copy an existing Profile to a location of your choice, here C:\OperaProfile.
==> Avoid spaces in all the pathes <==

Categories

Resources