0% found this document useful (0 votes)
58 views

Scripts

The document contains code for applying coupon codes during checkout on an e-commerce site. It logs in, adds items to the cart, and then enters a coupon code before completing checkout.

Uploaded by

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

Scripts

The document contains code for applying coupon codes during checkout on an e-commerce site. It logs in, adds items to the cart, and then enters a coupon code before completing checkout.

Uploaded by

Suraj Sahoo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 9

ApplyCouponCode

public static void main(String[] args) throws InterruptedException {

System.setProperty("webdriver.chrome.driver","E:\\\\Selenium\\\\chromedriver.exe");
WebDriver driver = new ChromeDriver();

driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.get("https://demo.opencart.com/");
driver.findElement(By.xpath("//span[@class='caret']")).click();
Thread.sleep(5000);
driver.findElement(By.xpath("//a[text()='Login']")).click();
Thread.sleep(5000);
driver.findElement(By.xpath("//input[@id='input-
email']")).sendKeys("[email protected]");
driver.findElement(By.xpath("//input[@id='input-
password']")).sendKeys("Suraj1234");
driver.findElement(By.xpath("//input[@type='submit']")).click();
driver.findElement(By.xpath("//a[text()='Laptops &
Notebooks']")).click();
driver.findElement(By.xpath("//a[text()='Show All Laptops &
Notebooks']")).click();
Thread.sleep(5000);

driver.findElement(By.xpath("//*[@id=\"content\"]/div[4]/div[1]/div/div[2]/div[1]/h
4/a")).click();
driver.findElement(By.xpath("//input[@id='input-option225']")).click();
driver.findElement(By.xpath("//input[@id='input-option225']")).clear();
driver.findElement(By.xpath("//input[@id='input-
option225']")).sendKeys("2011-04-23");
driver.findElement(By.xpath("//input[@id='input-quantity']")).click();
driver.findElement(By.xpath("//input[@id='input-quantity']")).clear();
driver.findElement(By.xpath("//input[@id='input-
quantity']")).sendKeys("2");
driver.findElement(By.xpath("//button[@id='button-cart']")).click();
driver.findElement(By.xpath("//i[@class='fa fa-shopping-
cart']")).click();
Thread.sleep(5000);
driver.findElement(By.xpath("//a[@class='accordion-toggle']")).click();
driver.findElement(By.xpath("//input[@id='input-
coupon']")).sendKeys("110011");
driver.findElement(By.xpath("//input[@id='button-coupon']")).click();
}
}

Runner

@RunWith(Cucumber.class)
@CucumberOptions(
features = "C:\\Users\\hp\\eclipse-workspace\\Cucumber\\Feature"
,glue = {"StepDefinition"}
,tags = {"@Login"}
,dryRun = false
)
public class Runner {

TC01_Login.feature

@FeatureName
Feature: Login Functionality

@Login
Scenario Outline: To check Login Functionality
Given User has access to the Application
When User select My Account
And User select Login
And User enter <Email> and <Password>
And User click on Login Button
Then User login to the application successfully

Examples:
| Email | Password |
| "[email protected]" | "Suraj1234" |

TC02_Register.feature

@FeatureName
Feature: Register Functionality

@Register
Scenario Outline: To check Register Functionality
Given User has access to the Application
When User select My Account
And User select Register
And User enter <firstname>, <lastname>, <email>, <telephone>, <password> and
<confirm>
And User check on Privacy Policy
And User click on Continue Button
Then User login to the application successfully

Examples:
| firstname | lastname | email | telephone | password
| confirm |
| "Suraj" | "Sahoo" | "[email protected]" | "7008266747" |
"Suraj1234" | "Suraj1234" |

TC01_login

WebDriver driver;

@Given("^User has access to the Application$")


public void user_has_access_to_the_Application() throws Throwable {

System.setProperty("webdriver.chrome.driver","E:\\Selenium\\chromedriver.exe");
driver = new ChromeDriver();

driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.get("https://demo.opencart.com/");
}

@When("^User select My Account$")


public void user_select_My_Account() throws Throwable {
driver.findElement(By.xpath("//span[@class='caret']")).click();
Thread.sleep(5000);
}

@When("^User select Login$")


public void user_select_Login() throws Throwable {
driver.findElement(By.xpath("//a[text()='Login']")).click();
Thread.sleep(5000);
}

@When("^User enter \"([^\"]*)\" and \"([^\"]*)\"$")


public void user_enter_and(String Email, String Password) throws Throwable {
driver.findElement(By.xpath("//input[@id='input-
email']")).sendKeys(Email);
driver.findElement(By.xpath("//input[@id='input-
password']")).sendKeys(Password);
}

@When("^User click on Login Button$")


public void user_click_on_Login_Button() throws Throwable {
driver.findElement(By.xpath("//input[@type='submit']")).click();
}

@Then("^User login to the application successfully$")


public void user_login_to_the_application_successfully() throws Throwable {
System.out.println("Login Success");
}
}

CouponCode

public static void main(String[] args) throws InterruptedException {

System.setProperty("webdriver.chrome.driver","E:\\\\Selenium\\\\chromedriver.exe");
WebDriver driver = new ChromeDriver();

driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.get("https://demo.opencart.com/");
driver.findElement(By.xpath("//span[@class='caret']")).click();
Thread.sleep(5000);
driver.findElement(By.xpath("//a[text()='Login']")).click();
Thread.sleep(5000);
driver.findElement(By.xpath("//input[@id='input-
email']")).sendKeys("[email protected]");
driver.findElement(By.xpath("//input[@id='input-
password']")).sendKeys("Suraj1234");
driver.findElement(By.xpath("//input[@type='submit']")).click();
driver.findElement(By.xpath("//a[text()='Laptops &
Notebooks']")).click();
driver.findElement(By.xpath("//a[text()='Show All Laptops &
Notebooks']")).click();
Thread.sleep(5000);

driver.findElement(By.xpath("//*[@id=\"content\"]/div[4]/div[1]/div/div[2]/div[1]/h
4/a")).click();
//driver.findElement(By.xpath("//input[@id='input-
option225']")).click();
driver.findElement(By.xpath("//input[@id='input-option225']")).clear();
driver.findElement(By.xpath("//input[@id='input-
option225']")).sendKeys("2011-04-23");
driver.findElement(By.xpath("//input[@id='input-quantity']")).click();
driver.findElement(By.xpath("//input[@id='input-quantity']")).clear();
driver.findElement(By.xpath("//input[@id='input-
quantity']")).sendKeys("2");
driver.findElement(By.xpath("//button[@id='button-cart']")).click();
driver.findElement(By.xpath("//i[@class='fa fa-shopping-
cart']")).click();
Thread.sleep(5000);
driver.findElement(By.xpath("//a[@class='accordion-toggle']")).click();
driver.findElement(By.xpath("//input[@id='button-coupon']")).click();
}
}

EditAccount

public static void main(String[] args) throws InterruptedException {

System.setProperty("webdriver.chrome.driver","E:\\\\Selenium\\\\chromedriver.exe");
WebDriver driver = new ChromeDriver();

driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.get("https://demo.opencart.com/");
driver.findElement(By.xpath("//span[@class='caret']")).click();
Thread.sleep(5000);
driver.findElement(By.xpath("//a[text()='Login']")).click();
Thread.sleep(5000);
driver.findElement(By.xpath("//input[@id='input-
email']")).sendKeys("[email protected]");
driver.findElement(By.xpath("//input[@id='input-
password']")).sendKeys("Suraj1234");
driver.findElement(By.xpath("//input[@type='submit']")).click();
driver.findElement(By.xpath("//a[text()='Edit
Account']")).click();
driver.findElement(By.xpath("//input[@id='input-
lastname']")).clear();
driver.findElement(By.xpath("//input[@id='input-
lastname']")).sendKeys("Auto");

driver.findElement(By.xpath("//input[@value='Continue']")).click();
Thread.sleep(5000);
driver.findElement(By.xpath("//*[@id=\"column-
right\"]/div/a[13]")).click();
Thread.sleep(5000);
driver.findElement(By.xpath("//a[text()='Continue']")).click();
}
}

ProductAvailability

public static void main(String[] args) throws InterruptedException {

System.setProperty("webdriver.chrome.driver","E:\\\\Selenium\\\\chromedriver.exe");
WebDriver driver = new ChromeDriver();

driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.get("https://demo.opencart.com/");
driver.findElement(By.xpath("//span[@class='caret']")).click();
Thread.sleep(5000);
driver.findElement(By.xpath("//a[text()='Login']")).click();
Thread.sleep(5000);
driver.findElement(By.xpath("//input[@id='input-
email']")).sendKeys("[email protected]");
driver.findElement(By.xpath("//input[@id='input-
password']")).sendKeys("Suraj1234");
driver.findElement(By.xpath("//input[@type='submit']")).click();

driver.findElement(By.xpath("//input[@name='search']")).sendKeys("Iphone");
driver.findElement(By.xpath("//button[@class='btn btn-default btn-
lg']")).click();
driver.findElement(By.xpath("//a[text()='iPhone']")).click();
driver.findElement(By.xpath("//input[@id='input-quantity']")).click();
driver.findElement(By.xpath("//input[@id='input-quantity']")).clear();
driver.findElement(By.xpath("//input[@id='input-
quantity']")).sendKeys("2");
driver.findElement(By.xpath("//button[@id='button-cart']")).click();
driver.findElement(By.xpath("//i[@class='fa fa-shopping-
cart']")).click();
driver.findElement(By.xpath("//i[@class='fa fa-share']")).click();

}
}

Register

public static void main(String[] args) throws InterruptedException {

System.setProperty("webdriver.chrome.driver","E:\\\\Selenium\\\\chromedriver.exe");
WebDriver driver = new ChromeDriver();

driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.get("https://demo.opencart.com/");
driver.findElement(By.xpath("//span[@class='caret']")).click();
Thread.sleep(5000);
driver.findElement(By.xpath("//a[text()='Register']")).click();
Thread.sleep(5000);
driver.findElement(By.xpath("//input[@id='input-
firstname']")).sendKeys("Suraj");
driver.findElement(By.xpath("//input[@id='input-
lastname']")).sendKeys("Sahoo");
driver.findElement(By.xpath("//input[@id='input-
email']")).sendKeys("[email protected]");
driver.findElement(By.xpath("//input[@id='input-
telephone']")).sendKeys("7008266747");
driver.findElement(By.xpath("//input[@id='input-
password']")).sendKeys("Suraj1234");
driver.findElement(By.xpath("//input[@id='input-
confirm']")).sendKeys("Suraj1234");

driver.findElement(By.xpath("//input[@type='checkbox']")).click();
driver.findElement(By.xpath("//input[@type='submit']")).click();

RegisterFailure

public static void main(String[] args) throws InterruptedException {

System.setProperty("webdriver.chrome.driver","E:\\\\Selenium\\\\chromedriver.exe");
WebDriver driver = new ChromeDriver();

driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.get("https://demo.opencart.com/");
driver.findElement(By.xpath("//span[@class='caret']")).click();
Thread.sleep(5000);
driver.findElement(By.xpath("//a[text()='Register']")).click();
Thread.sleep(5000);
driver.findElement(By.xpath("//input[@id='input-
firstname']")).sendKeys("Suraj");
driver.findElement(By.xpath("//input[@id='input-
lastname']")).sendKeys("Sahoo");
driver.findElement(By.xpath("//input[@id='input-
email']")).sendKeys("[email protected]");
driver.findElement(By.xpath("//input[@id='input-telephone']")).clear();
driver.findElement(By.xpath("//input[@id='input-
password']")).sendKeys("Suraj1234");
driver.findElement(By.xpath("//input[@id='input-
confirm']")).sendKeys("Suraj1234");
driver.findElement(By.xpath("//input[@type='checkbox']")).click();
driver.findElement(By.xpath("//input[@type='submit']")).click();
}
}

RemoveProduct

public static void main(String[] args) throws InterruptedException {


System.setProperty("webdriver.chrome.driver","E:\\\\Selenium\\\\chromedriver.exe");
WebDriver driver = new ChromeDriver();

driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.get("https://demo.opencart.com/");
driver.findElement(By.xpath("//span[@class='caret']")).click();
Thread.sleep(5000);
driver.findElement(By.xpath("//a[text()='Login']")).click();
Thread.sleep(5000);
driver.findElement(By.xpath("//input[@id='input-
email']")).sendKeys("[email protected]");
driver.findElement(By.xpath("//input[@id='input-
password']")).sendKeys("Suraj1234");
driver.findElement(By.xpath("//input[@type='submit']")).click();
driver.findElement(By.xpath("//a[text()='Laptops &
Notebooks']")).click();
driver.findElement(By.xpath("//a[text()='Show All Laptops &
Notebooks']")).click();

driver.findElement(By.xpath("//*[@id=\"content\"]/div[4]/div[1]/div/div[2]/div[1]/h
4/a")).click();
driver.findElement(By.xpath("//button[@id='button-cart']")).click();
driver.findElement(By.xpath("//i[@class='fa fa-shopping-
cart']")).click();
driver.findElement(By.xpath("//i[@class='fa fa-times-
circle']")).click();
Thread.sleep(5000);
driver.findElement(By.xpath("//a[@class='btn btn-primary']")).click();

}
}

Tab

public static void main(String[] args) throws InterruptedException {

System.setProperty("webdriver.chrome.driver","E:\\\\Selenium\\\\chromedriver.exe");
WebDriver driver = new ChromeDriver();

driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.get("https://demo.opencart.com/");
driver.findElement(By.xpath("//span[@class='caret']")).click();
Thread.sleep(5000);
driver.findElement(By.xpath("//a[text()='Login']")).click();
Thread.sleep(5000);
driver.findElement(By.xpath("//input[@id='input-
email']")).sendKeys("[email protected]");
driver.findElement(By.xpath("//input[@id='input-
password']")).sendKeys("Suraj1234");
driver.findElement(By.xpath("//input[@type='submit']")).click();
Thread.sleep(5000);

driver.findElement(By.xpath("//*[@id=\"menu\"]/div[2]/ul/li[1]/a")).click();
driver.findElement(By.xpath("//*[@id=\"menu\"]/div[2]/ul/li[1]/div/div/ul/li[2]/a")
).click();

driver.findElement(By.xpath("//*[@id=\"content\"]/div[2]/div/div/div[2]/div[2]/butt
on[1]/i")).click();

UploadFile

public static void main(String[] args) throws InterruptedException {

System.setProperty("webdriver.chrome.driver","E:\\\\Selenium\\\\chromedriver.exe");
WebDriver driver = new ChromeDriver();

driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.get("https://demo.opencart.com/");
driver.findElement(By.xpath("//span[@class='caret']")).click();
Thread.sleep(5000);
driver.findElement(By.xpath("//a[text()='Login']")).click();
Thread.sleep(5000);
driver.findElement(By.xpath("//input[@id='input-
email']")).sendKeys("[email protected]");
driver.findElement(By.xpath("//input[@id='input-
password']")).sendKeys("Suraj1234");
driver.findElement(By.xpath("//input[@type='submit']")).click();
driver.findElement(By.xpath("//a[text()='Components']")).click();
driver.findElement(By.xpath("//a[text()='Monitors (2)']")).click();
driver.findElement(By.xpath("//a[text()='Apple Cinema
30\"']")).click();
driver.findElement(By.xpath("//input[@value='10']")).click();
driver.findElement(By.xpath("//input[@value='test']")).click();
Select dropdown = new
Select(driver.findElement(By.name("option[217]")));
dropdown.selectByVisibleText("Blue (+$3.00)");
driver.findElement(By.xpath("//textarea[@id='input-
option209']")).sendKeys("abcdefg");
driver.findElement(By.xpath("//input[@id='input-option219']")).clear();
driver.findElement(By.xpath("//input[@id='input-
option219']")).sendKeys("2021-04-22");
driver.findElement(By.xpath("//input[@value='2011-02-20
22:25']")).clear();
driver.findElement(By.xpath("//input[@value='2011-02-20
22:25']")).sendKeys("2021-04-22 22:25");
driver.findElement(By.xpath("//button[text()='Add to Cart']")).click();

VerifyTitle
public static void main(String[] args) throws InterruptedException {

System.setProperty("webdriver.chrome.driver","E:\\\\Selenium\\\\chromedriver.exe");
WebDriver driver = new ChromeDriver();

driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.get("https://demo.opencart.com/");
driver.findElement(By.xpath("//span[@class='caret']")).click();
Thread.sleep(5000);
driver.findElement(By.xpath("//a[text()='Login']")).click();
Thread.sleep(5000);
driver.findElement(By.xpath("//input[@id='input-
email']")).sendKeys("[email protected]");
driver.findElement(By.xpath("//input[@id='input-
password']")).sendKeys("Suraj1234");
driver.findElement(By.xpath("//input[@type='submit']")).click();
Thread.sleep(5000);
driver.findElement(By.xpath("//i[@class='fa fa-home']")).click();

You might also like