Selenium tutorial for beginners
Introduction
- Selenium is an open-source web-based automation tool.
- It is an automation testing suite for web application across different browsers.
- Selenium integrate to multiple tools like test-ng ,JUnit.
- It is using run the tests in multiple browsers at a time.
- The Selenium-IDE (Integrated Development Environment) it is easy to use develop selenium test cases. GUI for recording user actions and workflow.
- Selenium grid is a tool, run parallel tests across different machines and different browsers.
- Selenium web driver uses to Develop the script.
- It supports only web-based applications.
Environment setup
- Download the java and install it (If you have already installed, please ignore it).
- Download the eclipse and install it. (If you have already installed, please ignore it).
- Then you need to install firebug and fire-path extensions for firefox browser. For chrome FirePHP extension install it.
- By the use of firebug and fire-path, we can get the id or XPath of the element.
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class Linkedinn {
public static void main(String[] args) {
// declaration and instantiation of objects/variables
System.setProperty("webdriver.ie.driver","C:\\Users\\miracle\\Downloads\\IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver();
String baseUrl = "https://www.linkedin.com/";
driver.get(baseUrl);
// Get the WebElement corresponding to the Email Address(TextField)
WebElement email = driver.findElement(By.id("login-email"));
// Get the WebElement corresponding to the Password Field
WebElement password = driver.findElement(By.name("login-password"));
email.sendKeys("your email id");
password.sendKeys("your pasword");
System.out.println("Text Field Set");
// Deleting values in the text box
email.clear();
password.clear();
System.out.println("Text Field Cleared");
// Find the submit button
WebElement login = driver.findElement(By.id("login-submit"));
login.click();
System.out.println("Login Done with Click");
driver.close();
}
}
Explanation:
- First Download the driver from selenium official website https://www.seleniumhq.org/
- Download the web driver which browser you want to run all test cases.
- Then set the property for driver location where you placed the driver .exe file.
- Create the object for Driver class and based on the driver object pass the values statically.
- Use the predefined methods to pass the data into input fields.
- The driver.get method is used to navigate the page which you provided in the base URL.
0 Response to "Selenium tutorial for beginners"
Post a Comment