Selenium
It is a popular open-source web-based automation tool. In this tutorial,we will learn how to install Selenium Webdriver.
Steps to be followed:
- Download and setup Selenium server
- Downloading ChromeDriver
- Integrating selenium to Eclipse
Step 1: Download and setup Selenium server
-
Locate selenium using
locate selenium
command. If it is not present, then use the following command to update the packages.
sudo apt-get update
-
Install selenium using below command:
sudo pip install selenium
-
If downloading Selenium through the command line seems impossible,you can take this link
https://www.selenium.dev/downloads/.
Immediately, you will be able to see the selenium server in the downloads section of your system
Step 2: Downloading ChromeDriver
-
Download the most preferable version. To execute the same, find out the Google chrome version available in your system. Open Google Chrome >> Click on three dots >> Help >> About Google Chrome.
-
Now you can see the Google Chrome Version.
-
Go to ChromeDriver downloads and select the version as shown below.
-
You will be redirected to the page shown below. Select for Linux zip file.
-
Now find the downloaded file in your system. For that you must extract the zip file. Ensure to copy the path and keep it for use.
Step 3: Integrating Selenium to Eclipse
- From your desktop, open the eclipse. Develop a new Java project in Eclipse. Right click on the project and make a new package. Once it is created, build a new class inside the package.
-
Further, configure the build path just by doing a right click on the developed project as shown below.
-
Click on Add external jar files for Selenium as shown below. The pop-up window will appear and will ask to select a file. Choose the Selenium jar file in the downloads section.
- Click on Apply and Close.
-
You can see the referenced jar files as shown below.
Let’s have a look at hands-on Demo (Selenium – Test Case)
A test case is written for logging into yahoo.com.
- Create a one
first.java
file to setup the selenium server jar file. Then we create a web driver instance for the same. And finally, we use
driver.get()
navigating to the respective URL and passing the username for the same.
-
Write the following code in the first.java file.
package test;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class first {
public static void main(String[] args) throws InterruptedException {
System.setProperty(“webdriver.chrome.driver”, “/Path_To_Your_Chrome_Driver”);
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get(“https://login.yahoo.com”);
driver.findElement(By.xpath(“//input[@id=’login-username’]”)).sendKeys(“[email protected]”);
}
}
- Right click on the written code and select Run As -> Java Application.
-
On executing the test case, you can see the output as shown below.
TestNG
Steps to be followed:
- Download and set up TestNG
- Integrate TestNG in Eclipse
Step 1: Downloading and set up TestNG
- Open the terminal and type the command given below to download the TestNG.
wget http://www.java2s.com/Code/JarDownload/testng/testng-6.8.7.jar.zip
-
Unzip the TestNG jar file using the command given below:
unzip tes tng-6.8.7.jar.zip
-
You can see the testng same as selenium server in the downloads section.
Step 2: Integrating TestNG in Eclipse
-
Go to the project in eclipse, right click on the project, select Build Path, and select Configure Build Path. Select Libraries and click on Add External JARs…. Browse and select the TestNG jar file. Refer to Lesson 6 Demo 1 to know how to configure the build path.
- Click on Apply and Close.
-
You can see the referenced jar files for Testng as shown in the image below.
-
Go to the Help tab in the Eclipse and choose Eclipse Marketplace to configure TestNg.
-
Type TestNg in the find bar and click on Install. Select TestNG for Eclipse as shown in the below screenshot.
- Once the installation is done, click on Confirm.
- Select the checkbox I accept the terms of the license agreement and click on Finish.
A Glimpse into the Hands-on-Demo (TestNG – Test Case)
So, this is the place where we began to write the test case that the web page title should be the “Google”. Otherwise it failed the test case.
Testing the automation script