22 – Selenium Test Environment Setup
Selenium Class 22: Selenium Test Environment Setup
i) Selenium Test Environment Setup
First choose Selenium Tools and Other Components for Testing,
Example: Eclipse IDE for writing Test Scripts, Java for programming, TestNG as Test Runner…..
Steps:
1) Download & Install Java Software (JDK) – create and execute programs/test scripts
2) Set Environment Variable path (Path variable) – to use Java software from any directory
3) Download Eclipse IDE and extract – to write and execute Java programs, add software components…
4) Download Selenium WebDriver Java language binding (from www.seleniumhq.org) and add WebDriver jar files to Java project in Eclipse IDE.
5) Download Browser driver/s and set browser path in test cases (instantiate Browser driver)
……………………………………………………………..
Navigation to add Selenium jar files to Java Project in Eclipse IDE,
- Launch Ellipse IDE
- Create Java Project /Select Java Project and right Click
- Build path
- Configure Build path
- Select “Libraries” tab
- Add “External jars”
- Browse path of the WebDriver jar files and Add
- OK
……………………………………………………………..
ii) Write first Selenium Test Case & Execute
Manual Test Case:
Test Case ID: gcrShop_admin_TC001
Test Case Name: Verify Admin Login into gcrShop Application Admin Interface
Test Steps:
1) Launch Browser
2) Navigate to gcrShop Admin Interface (“http://www.gcrit.com/build3/admin/”)
3) Enter valid Username
4) Enter valid Password
5) Click Login
…………………….
Input Data: admin
Password: admin@123
Verification Point:
Capture the current URL after Login and compare with expected
Expected URL: http://www.gcrit.com/build3/admin/index.php
Actual: * After Execution
Test Result: Pass/Fail (* After Execution)
……………………………………………………………..
Inspect Elements:
i) Username – Edit Box – name – username
ii) Password – Edit Box – name – password
iii) Login – Button – id- tdb1
……………………………………………………………..
Download Browser driver/s and Instantiate in your Test Case
a) Admin Login Test Case using Google Chrome Browser
public class AdminLogin {
public static void main(String[] args) throws InterruptedException {
//Instantiate Chrome Browser Driver
System.setProperty(“webdriver.chrome.driver”, “E:/chromedriver.exe”);
//Create Chrome Browser Driver
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get(“http://www.gcrit.com/build3/admin/”);
driver.findElement(By.name(“username”)).sendKeys(“admin”);
driver.findElement(By.name(“password”)).sendKeys(“admin@123”);
driver.findElement(By.id(“tdb1”)).click();
Thread.sleep(3000);
String url = driver.getCurrentUrl();
if (url.contains(“http://www.gcrit.com/build3/admin/index.php”)){
System.out.println(“Admin Login is Successful -Passed”);
}
else
{
System.out.println(“Admin Login is Unsuccessful – Failed”);
}
driver.close();
}
}
b) Admin Login Test Case using Mozilla Firefox Browser
public class AdminLogin {
public static void main(String[] args) throws InterruptedException {
//Instantiate Mozilla Firefox Browser Driver
System.setProperty(“webdriver.gecko.driver”, “E:/geckodriver.exe”);
//Create Mozilla Firefox Browser Driver
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get(“http://www.gcrit.com/build3/admin/”);
driver.findElement(By.name(“username”)).sendKeys(“admin”);
driver.findElement(By.name(“password”)).sendKeys(“admin@123”);
driver.findElement(By.id(“tdb1”)).click();
Thread.sleep(3000);
String url = driver.getCurrentUrl();
if (url.contains(“http://www.gcrit.com/build3/admin/index.php”)){
System.out.println(“Admin Login is Successful -Passed”);
}
else
{
System.out.println(“Admin Login is Unsuccessful – Failed”);
}
driver.close();
}
}
……………………………………………………………..
c) Admin Login Test Case using MS Edge Browser
public class AdminLogin {
public static void main(String[] args) throws InterruptedException {
//Instantiate MS Edge Browser Driver
System.setProperty(“webdriver.edge.driver”, “E:/MicrosoftWebDriver.exe”);
//Create MS Edge Browser Driver
WebDriver driver = new EdgeDriver();
//driver.manage().window().maximize();
driver.get(“http://www.gcrit.com/build3/admin/”);
driver.findElement(By.name(“username”)).sendKeys(“admin1”);
driver.findElement(By.name(“password”)).sendKeys(“admin@123”);
driver.findElement(By.id(“tdb1”)).click();
Thread.sleep(3000);
String url = driver.getCurrentUrl();
if (url.contains(“http://www.gcrit.com/build3/admin/index.php”)){
System.out.println(“Admin Login is Successful -Passed”);
}
else
{
System.out.println(“Admin Login is Unsuccessful – Failed”);
}
driver.close();
}
}
……………………………………………………………..