HomeSelenium

Selenium WebDriver – Executing Selenium Scripts on Opera Browser

Selenium WebDriver – Executing Selenium Scripts on Opera Browser

Selenium WebDriver – Executing Selenium Scripts on Opera Browser

Prerequisite / Assumptions

  • You have installed latest version of opera browser in your machine.
  • You have JDK installed and configured in your machine,
  • You have latest version of eclipse IDE installed in your machine
  • Operating System in your machine is Windows

Create Maven Project

  • Open your Eclipse IDE by double-clicking on eclipse.exe
  • Select File > New Project will open a create maven project wizard
  • Select Maven Project under the Maven folder and click Next till you find a window asking Select an Archetype
  • Enter in a Filter maven-archetype-quickstart and allow search
  • Search should display two artifact id, as found in image below

 

filter  for maven-archetype-quickstart text
  • Select apache.maven.archetype Group ID with Artifact ID maven-archetype-quickstart from the filtered items
  • Click Next button
  • A window with heading Specify Archetype parameters will open
  • Enter Group Id as anything say Demo
  • Enter Artifact Id as Project name say – SeleniumOperaDemo
  • Package will be Demo. SeleniumOperaDemo
  • You can give any other value for Group Id and Package
  • Click on Finish

You will find Maven project under Project Explorer with name SeleniumOperaDemo

( You can able to view Project Explorer from Window > Show View > Project Explorer)

  • Expand The Project folder by clicking on Project name
  • Expand src/test/java folder to view package Demo. SeleniumOperaDemo
  • Expaning Demo. SeleniumOperaDemo package,
  • You will find default java file AppTest.java. Delete this Java file

  • Now select package Demo.SeleniumOperaDemo
  • Right Click on this package and select New > Class
  • In a window with a title Java Class, Enter Name as Demo
  • Select check box next to public static void main(String[] args) so that main method will be auto inserted into Demo class
  • Click on Finish
  • You will find Demo.java class will get created and its content can be seen in right panel
  • Write a statement of code inside the main method in order to execute your code and open Opera browser

You can generate an object of class WebDriver as follows

WebDriver driver = new OperaDriver();

You will find red lines under WebDriver and OperaDriver and you won’t find any import suggestion when you hover mouse over these classes as your Project is not yet configured with Selenium Java.

Configure Maven project with Selenium Java

  • You can find pom.xml file at the end of project trail.
  • Double click to open pom.xml file to read the contents inside it
  • you will find dependencies contains default dependency for JUnit, you can delete it

 

 

 

 

 

  • You will have <dependencies> </dependencies> folder now
  • Now open new tab and search for mvnrepository.com and search for Selenium Java

http://www.mvnrepository site

Click on Selenium Java hyperlink from Apache, you will find pink background alpha version which are not stable

display stable version 3.141.59 for selenium java
  • The most stable version for Selenium Java is 3.141.59,
  • Click on it.
  • Select dependency text for Maven & copy them

 

 

 

 

 

 

 

dependency code for selenium java
  • Paste the copied dependency text from Selenium Java 3.141.59, Maven dependency for Selenium Java, into pom.xml file inside <dependencies> </dependencies>.
  • Save pom.xml file and close it.
  • Now hover over Classes WebDriver and OperaDriver, you now will get import suggestion as your project is now configured with Selenium Java.
  • You can select import statement and accept the imports
  • You will notice import statements above your class

 

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.opera.OperaDriver;

  • Try to run the project by right click on project and selecting Run as > Java Application
  • You will get an error webdriver.opera.driver for system property
  • You need to add system property in your code as below
System.setProperty for opera driver
  • Right click on project SeleniumOperaDemo and select New > Folder
  • Give name of folder as driver
  • You will save opera driver inside this driver folder & give this path inside “path”, so that system property will be able to find opera driver

If Opera browser is not available in your machine you can go to opera.com/download and click on Windows button to download Windows compatible browser, once downloaded, you can open it by double clicking on opera.exe

Opera browser will look like below

Opera Browser will look like this

You can check the version of opera browser by selecting O icon on left hand uppermost top corner, and going to help menus and about Opera submenus.

            finding version of opera browser

You need to download opera driver version compatible with our opera browser version

  • Go to official webpage of selenium which is selenium.dev/download to download opera driver

 

  • Where in you will find Browser pane
  • Under this you will find Opera
  • Click on documentation

Go to Opera and click on documentation for Opera driver
  • Check on Opera Driver version and corresponding Browser version
  • We have Opera Browser version 70, hence we can download

 

 

Driver compatible with version

 

Once downloaded save the OperaDriver zip file and check operadriver.exe file after unzip.

Copy operadriver.exe in driver folder location that we created under the eclipse project.

Check the property of the operadriver.exe file and select location & copy it in the path as below

Now you right some code so that opera browser will open with your above code

Write following automation code

driver.manage().window().maximize();

driver.get(“http://tutorialsninja.com/demo/”);

Inside the tutorialninja.com web site

  • Check the search text field attributes value,
  • By right clicking and inspecting the element. The html code for search box field will have name as search
  • Copy this name attribute

 

  • EnterfindElement(By.name(“search”)).sendKeys(“ipod”);

The code inside eclipse code will look like this

Running above code by Right Clicking on Project and selecting Run As à Java Application will open Opera Browser and go to specified web page and enter text iphone inside search box element as shown in image below

So the entire code to automate Opera browser using selenium Java is as mentioned below.

package Demo.SeleniumOperaDemo;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.opera.OperaDriver;
public class Demo {
public static void main(String[] args) {
System.setProperty("webdriver.opera.driver","C:\\Users\\jac\\eclipse-workspace\\SeleniumOperaDemo\\driver\\operadriver.exe");
WebDriver driver = new OperaDriver();
driver.get("http://tutorialsninja.com/demo/");
driver.findElement(By.name("search")).sendKeys("iphone");
}
}

 

Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *

For FREE Testing Tutorials & Videos

X
Open chat
Contact Us on Whatsapp