Automation testing using Selenium Web Driver
Definition
Selenium WebDriver is an assortment of open source APIs which are utilized to computerize the testing of a web application.
Description
- Selenium WebDriver device is utilized to automate web application testing to confirm that it fills in true to form.
- It supports numerous browsers, for example, Firefox, Chrome, IE, and Safari. Nonetheless, utilizing the Selenium WebDriver, we can automate testing for web applications.
- It also supports different programming languages such as C#, Java, Perl, PHP and Ruby for writing test scripts.
- It is an platform independent as we can use same code on different Operating Systems like Windows, Linux
TESTING PROCEDURE
Selenium WebDriver
Step-1
Go to the Link to download https://www.selenium.dev/downloads/
Click on Latest Stable Version to download
Step-2
Download Chromedriver
Go to Link https://chromedriver.chromium.org/downloads
Step-3
Extract You two files Selenium Server and ChromeDriver
Step-4
Now to go Chrome settings(As I am using Chrome for this testing ) and click on “About Chrome” to update driver Version
Step-5
Open Eclipse and make project
Now go to Refrenced Libraries and “Add External Jar’s”
Note:- You will get these JAR’s in Selenium Folder
Step-6
Create a Class in the Project and write code
Code
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) {
// declaration and instantiation of objects/variables
System.setProperty(“webdriver.chrome.driver”, “C:\\SELENIUM\\ChromeDriver\\chromedriver.exe”);
WebDriver driver=new ChromeDriver();
// Launch website
driver.navigate().to(“http://www.google.com/");
// Click on the search text box and send value
driver.findElement(By.name(“q”)).sendKeys(“java tutorials”);
// Click on the search button
driver.findElement(By.name(“btnK”)).click();
}
}
Run As > Java Application
Output:
Video Link for my Execution:- https://youtu.be/I3zDYkA6rU8
Step-7
Now make another class to get details of your web-Browser
Code
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Web_command {
public static void main(String[] args) {
// System Property for Chrome Driver
System.setProperty(“webdriver.chrome.driver”,”D:\\ChromeDriver\\chromedriver.exe”);
// Instantiate a ChromeDriver class.
WebDriver driver=new ChromeDriver();
// Storing the Application Url in the String variable
String url = (“https://www.google.co.in/");
//Launch the ToolsQA WebSite
driver.get(url);
// Storing Title name in the String variable
String title = driver.getTitle();
// Storing Title length in the Int variable
int titleLength = driver.getTitle().length();
// Printing Title & Title length in the Console window
System.out.println(“Title of the page is : “ + title);
System.out.println(“Length of the title is : “+ titleLength);
// Storing URL in String variable
String actualUrl = driver.getCurrentUrl();
if (actualUrl.equals(“https://www.google.co.in/")){
System.out.println(“Verification Successful — The correct Url is opened.”);
}
else{
System.out.println(“Verification Failed — An incorrect Url is opened.”);
}
// Storing Page Source in String variable
String pageSource = driver.getPageSource();
// Storing Page Source length in Int variable
int pageSourceLength = pageSource.length();
// Printing length of the Page Source on console
System.out.println(“Total length of the Pgae Source is : “ + pageSourceLength);
//Closing browser
driver.close();
}
}
Run as → Java application
Output: