0% found this document useful (0 votes)
8 views4 pages

Selenium Java Test Suite Guide

Testing

Uploaded by

Sujatha Gopala
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views4 pages

Selenium Java Test Suite Guide

Testing

Uploaded by

Sujatha Gopala
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

12.

Practical Exercise: Build a Test Suite with End-to-End


Automation in Selenium (Java)

1.​ Create Eclipse Java Project


a.​ In Eclipse: Click File → New -> Other → Select Java Project
b.​ Set Project name saucedemo-automation . and select Use an execution
environment as java1.8,Click finish
c.​ Right-click your project → Build Path → Configure Build Path
d.​ Go to the Libraries tab → Click Add External JARs
e.​ Now Add selenium-server
f.​ Click Apply and Save
2.​ Right Click on src on the project, → New → Class
a.​ Set class name AddToCartTestclick finish
b.​ Add Program

import [Link];
public class AddToCartTest extends LoginTest {
public void addItemToCart() throws InterruptedException {
login();
[Link](1000);

🛒
[Link]([Link]("add-to-cart-sauce-labs-backpack")).click();
[Link](" Item added to cart.");
}
}

3.​ Right Click on src on the project, → New → Class


a.​ Set class name BaseTest finish
b.​ Add Program

import [Link];
import [Link];
public class BaseTest {
protected WebDriver driver;
public void setup() {
driver = new ChromeDriver();
[Link]().window().maximize();
}
public void teardown() {
if (driver != null) {
[Link]();
}
}
}

4.​ Right Click on src on the project, → New → Class


a.​ Set class name CheckoutTest finish
b.​ Add Program

​ import [Link];
public class CheckoutTest extends LoginTest {
public void completeCheckout() throws InterruptedException {
login();
[Link]([Link]("add-to-cart-sauce-labs-backpack")).click();
[Link]([Link]("shopping_cart_link")).click();
[Link]([Link]("checkout")).click();
[Link]([Link]("first-name")).sendKeys("John");
[Link]([Link]("last-name")).sendKeys("Doe");
[Link]([Link]("postal-code")).sendKeys("12345");
[Link]([Link]("continue")).click();


[Link]([Link]("finish")).click();
[Link](" Checkout completed successfully.");
}
}

5.​ Right Click on src on the project, → New → Class


a.​ Set class name InventoryObjectCount finish
b.​ Add Program

​ import [Link];
import [Link];
import [Link];
public class InventoryObjectCount extends LoginTest {
public void countObjects() throws InterruptedException {
login();
[Link](2000);

🔍
List<WebElement> allElements = [Link]([Link]("//*"));
[Link](" Total elements on inventory page: " + [Link]());
}
}

6.​ Right Click on src on the project, → New → Class


a.​ Set class name LoginTest finish
b.​ Add Program

​ import [Link];
public class LoginTest extends BaseTest {
public void login() {
setup();
[Link]("[Link]
[Link]([Link]("user-name")).sendKeys("standard_user");
[Link]([Link]("password")).sendKeys("secret_sauce");
[Link]([Link]("login-button")).click();
}
}
7.​ Right Click on src on the project, → New → Class
a.​ Set class name LogoutTest finish
b.​ Add Program

​ import [Link];
public class LogoutTest extends LoginTest {
public void logout() throws InterruptedException {
login();
[Link](1000);
[Link]([Link]("react-burger-menu-btn")).click();
[Link](1000);

🚪
[Link]([Link]("logout_sidebar_link")).click();
[Link](" Logged out.");
}
}

8.​ Right Click on src on the project, → New → Class


a.​ Set class name Main finish
b.​ Add Program

public class Main {


public static void main(String[] args) throws InterruptedException {
InventoryObjectCount objCount = new InventoryObjectCount();
[Link]();
[Link]();
AddToCartTest add = new AddToCartTest();
[Link]();
[Link]();
CheckoutTest checkout = new CheckoutTest();
[Link]();
[Link]();
LogoutTest logout = new LogoutTest();
[Link]();
[Link]();
}
}

9.​ Run class Main

Output:- Opened wikipedia and closed

Output (Console)

🛒
Total elements on inventory page: 140


Item added to cart.

🚪
Checkout completed successfully.
Logged out.

You might also like