OperaDriver not working - c#

Using Selenium Grid2 and RemoteWebDriver in an MSTest class, I am struggling to get OperaDriver working.
I create the Selenium hub and Opera node by running the following commands in CMD:
start java -jar selenium-server-standalone-2.30.0.jar -role hub
start java -jar selenium-server-standalone-2.30.0.jar -role node -port 7001 -browser "browserName=opera,version=11.62,maxInstances=5,platform=WINDOWS" -hub http://localhost:4444/grid/register
And this works fine, I can the see the registered node when I view my hub in a browser.
But I get an exception whenever I try to create a new WebDriver in my C# test class:
DesiredCapabilities operaCapabilities = DesiredCapabilities.Opera();
operaCapabilities.SetCapability(CapabilityType.BrowserName, "opera");
operaCapabilities.SetCapability(CapabilityType.Platform, "WINDOWS");
operaCapabilities.SetCapability(CapabilityType.Version, "11.62");
operaCapabilities.SetCapability("opera.binary", "C:\\Program Files\\Opera\\opera.exe");
operaCapabilities.SetCapability("opera.port", 7001);
RemoteWebDriver operaDriver = new RemoteWebDriver(operaCapabilities);
Actually I get two different exceptions - the first time after creating the hub and node in Selenium I get this:
Could not find a platform that supports bundled launchers, please set
it manually
Build info: version: '2.30.0', revision: 'dc1ef9c', time: '2013-02-19
00:15:27'
System info: os.name: 'Windows 8', os.arch: 'x86', os.version: '6.2',
java.version: '1.7.0_15'
Driver info: driver.version: OperaDriver
And everytime after that I get the following error:
Could not initialize class
com.opera.core.systems.runner.launcher.OperaLauncherRunner
I am using Selenium-standalone-2.30.0.
I was using Opera version 12.14 but downgraded to 11.62 after I saw a list of compatible versions on the OperaDriver wiki page but the errors remain the same.
I have tried initialising the RemoteWebDriver with and without the capabilities above and get the same result every time.
Does anyone know what the problem is here and how to get a RemoteWebDriver working with Opera in this way?
Edit: Could it be that the platform for Opera version 12.14 reads as 'WINDOWS 8', and version 11.62 reads as "WIN32" when I open the Opera browser and view Help => About? As I am specifying the platform as WINDOWS in the node and RemoteWebDriver. If I try to specify WINDOWS 8 as the platform for the RemoteWebDriver an new exception is thrown where it can't find matching enum:
org.openqa.selenium.WebDriverException:
java.lang.IllegalArgumentException: No enum constant
org.openqa.selenium.Platform.WINDOWS 8
Edit2: For some reason CurrentPlatform is returning Vista for me, even though I am running Windows8.
Platform platform = Platform.CurrentPlatform;
And I also noticed that the OperaDriver source code checks for 'VISTA' in uppercase whereas the Platform in C# reads as 'Vista'.
Could this be causing the problem?

I've been suffering from this problem as well and thanks to the hint from eviltester I was able to solve the issue by using the following command line to start the selenium server:
java -Dos.name=windows -jar selenium-server-standalone-2.32.0.jar
The use of -Dos.name=windows is the equivalent of System.setProperty("os.name", "windows") and will allow your C# selenium code to work for the Opera browser.

I saw this when running in Java. In debug mode it looked like a possible omission in OperaLauncherRunner.java launcherNameForOS does not cater for the WIN8 enum returned by Platform.getCurrent().
In Java I fudged it by setting the system property "os.name" to "windows" before creating a new OperaDriver. This forced the Platform.getCurrent to return XP which the opera launcher was happy with.
So in java I just used this hack:
System.setProperty("os.name","windows");
driver = new OperaDriver();

Related

Chrome failed to start: crashed in Selenium testing

I am using C# Selenium for automated testing, and after the most recent chromedriver update 89.0.4389.2300, Google chrome starts and crashes right away. The weirdest thing is that when I am running it on my local, everything works fine, but I am also using Azure pipelines to run my tests on a server. The server one gives me this:
OpenQA.Selenium.WebDriverException : unknown error: Chrome failed to start: crashed.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location C:\Program Files (x86)\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
I have googled around and tried things like adding chromeOptions.AddArgument("--no-sandbox") and chromeOptions.AddArguments("disable-dev-shm-usage") but nothing helps. Chrome on my server is updated to the correct version too. The tests run headless.
Anyone else is having this issue?
The error mentions that chromedriver could not bind to open debug port on running Chrome.
Possible cases I met with:
old version of Chrome browser or chromedriver - since some version the port has changed
wrong Chrome binary location (chromedriver is looking for C:\Program Files (x86)\Google\Chrome\Application\chrome.exe)

Chromedriver still only supports version 79 with updated driver

This is most likely a duplicate question, but in my looking around i couldnt find an answer that matches my question exactly.
I am using selenium and NUnit to run unit tests, due to circumstances I have not been working on it for a while, and now that I come back I get this error on all my chrome tests:
OneTimeSetUp: System.InvalidOperationException : session not created: This version of ChromeDriver only supports Chrome version 79 (SessionNotCreated)
I have updated the driver to make sure that wasn't the issue, but even using the version 83 one, I still get this same error.
The ChromeDriver in your Windows %PATH% is likely a different version. The updated driver you downloaded needs to be saved over top of the ChromeDriver in your path.
Open the command prompt
Type where ChromeDriver and press Enter.
Save the updated ChromeDriver in the folder specified in the output of the where command.
You should update the ChromeDriver in your project. It might be done via Tools -> NugetPages.

Selenium protect ports [duplicate]

My Chrome browser is updated to version 78 and when I tried to execute any code of automation, it shows the error
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
[1573451703.668][WARNING]: Timed out connecting to Chrome, retrying...
Nov 11, 2019 11:25:05 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
[1573451709.039][WARNING]: Timed out connecting to Chrome, retrying...
How can I fix it?
This error message...
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
[1573451703.668][WARNING]: Timed out connecting to Chrome, retrying...
Nov 11, 2019 11:25:05 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
[1573451709.039][WARNING]: Timed out connecting to Chrome, retrying...
...implies that the ChromeDriver was unable to initiate/spawn a new WebBrowser i.e. Chrome Browser session.
Analysis
The first log message:
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
is part of the startup log when using ChromeDriver and is informative in nature.
You can find a detailed discussion in How do I protect the ports that chromedriver use?
The following log message:
[1573451703.668][WARNING]: Timed out connecting to Chrome, retrying...
indicates there are some incompatibility between the version of the binaries you are using.
Solution
Ensure that:
JDK is upgraded to current levels JDK 8u222.
Selenium is upgraded to current levels Version 3.141.59.
ChromeDriver is updated to current ChromeDriver v78.0 level.
Chrome is updated to current Chrome Version 78.0 level. (as per ChromeDriver v78.0 release notes)
Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
(WindowsOS only) Use CCleaner tool to wipe off all the OS chores before and after the execution of your Test Suite.
(LinuxOS only) Free Up and Release the Unused/Cached Memory in Ubuntu/Linux Mint before and after the execution of your Test Suite.
If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client.
Take a System Reboot.
Execute your #Test as non-root user.
Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.
I have fixed this issue of timeout / Connection reset by changing my code from:
public void AfterScenario(Scenario sc) {
driver.close();
driver.quit();
driver = null;
}
to:
public void AfterScenario(Scenario sc) {
driver.quit();
driver = null;
}
So basically I removed the driver.close() and this fixed my issue. I do not know why this is happening, but experts can explain more...
I had to update to the dev version of chrome 79 and the latest dev version of chromedriver to make it work. Although I've run against other issues with this version, so I don't know if its a good solution.

Selenium Webdriver opens Firefox and then dies

I have a super simple test script (below) to get started with WebDriver. When I run the test (C# - Visual Studio 2015), it opens up a Firefox browser and then does nothing.
There are several posts out there that talk about the following issue, which I'm also getting:
OpenQA.Selenium.WebDriverException: Failed to start up socket within 45000 milliseconds. Attempted to connect to the following addresses: 127.0.0.1:7055.
But those posts regarding this problem are quite old and also have one major difference- their FF browser didn't open; mine does.
The error:
The code:
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
namespace seleniumDemo
{
[TestClass]
public class UnitTest1
{
static IWebDriver driverFF;
[AssemblyInitialize]
public static void SetUp(TestContext context)
{
driverFF = new FirefoxDriver();
}
[TestMethod]
public void TestFirefoxDriver()
{
driverFF.Navigate().GoToUrl("http://www.google.com");
driverFF.FindElement(By.Id("lst-ib")).SendKeys("Selenium");
driverFF.FindElement(By.Id("lst-ib")).SendKeys(Keys.Enter);
}
}
}
This question is different from what's been suggested as a duplicate because the FireFox browser actually opens in this case. In the other questions, it wasn't responding at all.
it seems to be related to Selenium and Firefox version incompatibility. I also faced the same error when selenium on my machine was unable to communicate to firefox. I upgraded firefox to 46.x and it started working.
You can find version compatibility information over web or refer selenium changelog as well.
Use MarrioneteDriver to use latest version of Firefox.
Below is the Java code, you can write in C# accordigly (Make sure you have geckodriver.exe under BrowserDriver folder in your project folder)
System.setProperty("webdriver.gecko.driver", System.getProperty("user.dir")+"/BrowserDrivers/geckodriver.exe");
DesiredCapabilities cap = DesiredCapabilities.firefox();
cap.setCapability("marionette", true);
WebDriver driver = new MarionetteDriver(cap);
You can download latest version of MarrioneteDriver from below :
https://github.com/mozilla/geckodriver/releases
And you should Marionette executable to Windows system path :
To add the Marionette executable to Windows system path you need
update the Path system variable and add the full directory to the
executable.
To do this, right-click on the Start menu and select System. On the
left-side panel click Advanced system settings and then Environment
Variables button from System Properties window. Now the only step left
to do is to edit Path system variable and add the full directory to
your geckodriver (you may need to add a semi-colon before doing this,
if not already present) and you’re good to go.
Then simply create your driver instance :
var driver = new FirefoxDriver(new FirefoxOptions());

Selenium with Microsoft Edge driver never finishes initialising

I'm using the C# bindings for Selenium and trying to get a simple automated test in Microsoft Edge working.
class Program
{
static void Main(string[] args)
{
EdgeOptions options = new EdgeOptions();
options.PageLoadStrategy = EdgePageLoadStrategy.Eager;
RemoteWebDriver driver = new EdgeDriver();
driver.Url = "http://bing.com/";
}
}
But the program halts on the initialisation of the EdgeDriver, the edge browser launches but the url never changes to "bing.com".
Has anyone else experienced this?
I have faced the same issue. I followed the below steps to resolve it :-
Download the correct Microsoft WebDriver server version for your build.
How to find your correct build number :-
1- Go to Start > Settings > System > About and locate the number next to OS Build on the screen. This is your build number. Having the correct version of WebDriver for your build ensures it runs correctly.
2- Run this command systeminfo | findstr /B /C:"OS Version" this will give the output like OS Version: 10.0.10586 N/A Build 10586. Here is build number is 10586
You need to check your Windows OS build number and download appropriate .msi and install it.
Provide the Syetem property where MicrosoftWebDriver.exe installed to webdriver.edge.driver.
Note :- The Default installed location of the MicrosoftWebDriver.exe :-
for 64 bit is C:\Program Files (x86)\Microsoft Web Driver
for 32 bit is C:\Program Files\Microsoft Web Driver
Hope it will work...:)
This happens when your system does not match the webdriver version... Determine which release of Windows 10 you are using... then go here and download same release..
https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver
Here's what the error looks like when the versions don't match.
Selenium will Hang
EdgeOptions options = new EdgeOptions();
options.PageLoadStrategy = EdgePageLoadStrategy.Eager;
RemoteWebDriver driver = new EdgeDriver();
driver.Url = "http://bing.com/";
Results in this exception with Edge still up and on the Bing page
Exception Thrown
changing the code to this, with no options:
var driver = new EdgeDriver();
driver.Url = "http://bing.com/";
Results in this:
Exception thrown: 'System.InvalidOperationException' in WebDriver.dll
And this in the console.
Something's not right with the MicrosoftWebDriver.Exe which was downloaded from here. https://www.microsoft.com/en-us/download/details.aspx?id=48212 and installed into the Program Files folder by default. Here's screenshot of add/remove programs. System is Windows 10 PRO 64 bit.
Note I did not try the 32 bit version

Categories

Resources