Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using C#, Selenium (3.141.0) and MSTest.TestFramework to test a fairly complex web site project. My goal is pretty straight forward - to test the site on a variety of browsers for the site (which is used worldwide).

There is no problem driving Chrome, Firefox and IE from Selenium. But I also want to test and support Opera - which is not so common in the US, but is very common elsewhere.

I am seeing articles that suggest that Opera is supportable, but I cannot get it to work.

The main instantiation (which fails) is:
iWebDriver driver = new OperaDriver();
I may be missing some arguments for the constructor, like perhaps a path for an Opera driver (I've downloaded operadriver.exe from https://github.com/operasoftware/operachromiumdriver/releases - and tried to add the path as a string argument - but that did not work.

I would appreciate any sample code guidance. There are lots of articles online about this topic - but i haven't yet found any code that works.

What I have tried:

Tried the constructor noted above
Posted
Updated 3-Apr-19 15:00pm
Comments
David_Wimbley 2-Apr-19 18:10pm    
Are you getting any errors? Have you tried using RemoteWebDriver and passing in browser settings that way?
Ken-in-California 2-Apr-19 19:00pm    
Hello David.
I tried instantiating with:
iWebDriver driver = new OperaDriver("C:\\Opera\\", operaOptions, TimeSpan.FromMinutes(1.0d));
The error I am getting is
OpenQA.Selenium.WebDriverException: 'unknown error: cannot find Opera binary
(Driver info: OperaDriver=2.42.3135 (O58),platform=Windows NT 10.0.17763 x86_64)'

BTW - "C:\\Opera\\" is the location of operadriver.exe - downloaded from at https://github.com/operasoftware/operachromiumdriver/releases.

I have not tried RemoteWebDriver, because I've encapsulated my browser choice - at the beginning of the tests the tester chooses which browsers to run on, and then I
pass a Chrome or Firefox or IE iWebDriver to the code for the selected test, and sequentially run the same test which each selected browser.
David_Wimbley 2-Apr-19 23:33pm    
Shouldn't you be specifying the exact EXE, not a relative path to the folder?
Ken-in-California 3-Apr-19 13:36pm    
David - I tried that first - I used "C:\\Opera\\operadriver.exe" - and the error I got was:

OpenQA.Selenium.DriverServiceNotFoundException: 'The file C:\Opera\operadriver.exe\operadriver.exe does not exist. The driver can be downloaded at https://github.com/operasoftware/operachromiumdriver/releases'

In light of the duplication I truncated my string at the slash.
Mehdi Gholam 3-Apr-19 3:47am    
Opera on the desktop uses the same engine as Chrome, so you it "should" act the same.

1 solution

I got it working - though imperfectly.

Step 1 - I downloaded the appropriate operadriver.exe binary from: https://github.com/operasoftware/operachromiumdriver/releases

I moved the operadriver.exe to "C:\\Opera\".

In my code I already setup an iWebDriver object named driver.

Opera was already installed on my system at the default location - as will be clear below.

Here's the code that worked...

C#
using OpenQA.Selenium;
using OpenQA.Selenium.Opera;
using OpenQA.Selenium.Support.UI;

OperaDriverService service = OperaDriverService.CreateDefaultService("C:\\Opera\\","operadriver.exe");
var operaOptions = new OperaOptions
   {
      BinaryLocation = "C:\\Users\\username\\AppData\\Local\\Programs\\Opera\\58.0.3135.127\\opera.exe",
                            LeaveBrowserRunning = false
   };
   driver = new OperaDriver(service, operaOptions);


The imperfection I am aware of right now is a "Manage Extensions" popup that shows up - i have been unable to suppress it so far - and do not want to suppress all popups because the site does generate some alerts/popups in certain testable situations.

I anyone has idea for suppressing that popup, I'd be appreciative of you sharing.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900