0% found this document useful (0 votes)
7 views3 pages

Drop Down

The document is a Java test class for Selenium WebDriver that automates the registration process on a demo e-commerce site and performs various dropdown selections. It includes methods for setting up the WebDriver, executing test cases for user registration, role selection, and interacting with dropdown menus. The test cases validate the expected outcomes and ensure the correct options are selected from the dropdowns.

Uploaded by

tannv.ytcvn
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)
7 views3 pages

Drop Down

The document is a Java test class for Selenium WebDriver that automates the registration process on a demo e-commerce site and performs various dropdown selections. It includes methods for setting up the WebDriver, executing test cases for user registration, role selection, and interacting with dropdown menus. The test cases validate the expected outcomes and ensure the correct options are selected from the dropdowns.

Uploaded by

tannv.ytcvn
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/ 3

package webdriver;

import org.testng.annotations.Test;

import org.testng.annotations.BeforeClass;

import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
import org.testng.Assert;
import org.testng.annotations.AfterClass;

public class Topic_08_Default_Dropdown {


WebDriver driver;
String projectPath = System.getProperty("user.dir");
String fName, lName, eMail, day, moth, year , company, pass;
Select select;
@BeforeClass
public void beforeClass() {
System.setProperty("webdriver.gecko.driver", projectPath + "\\
browserDrivers\\geckodriver.exe");
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
//driver.manage().window().maximize();

fName = "Jame";
lName = "Alex";
eMail = "[email protected]";
day = "6";
moth = "February";
year = "1990";
company = "Automation Testing";
pass = " 094582045";
}
//@Test
public void TC_01_Nopcommerce() {
driver.get("https://demo.nopcommerce.com/register");
driver.findElement(By.cssSelector(".ico-register")).click();
driver.findElement(By.id("gender-male")).click();
driver.findElement(By.id("FirstName")).sendKeys(fName);
driver.findElement(By.id("LastName")).sendKeys(lName);

select = new Select(driver.findElement(By.name("DateOfBirthDay")));


select.selectByVisibleText(day);
List<WebElement> alldayitems = select.getOptions();
Assert.assertEquals(alldayitems.size(),32);
Assert.assertEquals(select.getFirstSelectedOption().getText(), day);

select = new Select(driver.findElement(By.name("DateOfBirthMonth")));


select.selectByVisibleText(moth);

List<WebElement> allmonthitems = select.getOptions();


Assert.assertEquals(allmonthitems.size(),13);
Assert.assertEquals(select.getFirstSelectedOption().getText(), moth);
select = new Select(driver.findElement(By.name("DateOfBirthYear")));
select.selectByVisibleText(year);
List<WebElement> allyearitems = select.getOptions();
Assert.assertEquals(allyearitems.size(),112);
Assert.assertEquals(select.getFirstSelectedOption().getText(), year);

driver.findElement(By.id("Email")).sendKeys(eMail);
driver.findElement(By.id("Company")).sendKeys(company);
driver.findElement(By.id("Password")).sendKeys(pass);
driver.findElement(By.id("ConfirmPassword")).sendKeys(pass);

driver.findElement(By.id("register-button")).click();

Assert.assertEquals(driver.findElement(By.cssSelector("div.result")).getText(),
"Your registration completed");

driver.findElement(By.cssSelector("a.ico-account")).click();
select = new Select(driver.findElement(By.name("DateOfBirthDay")));
Assert.assertEquals(select.getFirstSelectedOption().getText(), day);

select = new Select(driver.findElement(By.name("DateOfBirthMonth")));


Assert.assertEquals(select.getFirstSelectedOption().getText(), moth);

select = new Select(driver.findElement(By.name("DateOfBirthYear")));


Assert.assertEquals(select.getFirstSelectedOption().getText(), year);

}
//@Test
public void TC_02_Role() {
driver.get("https://rode.com/en/support/where-to-buy");

select = new Select(driver.findElement(By.id("country")));

Assert.assertFalse(select.isMultiple());

select.selectByVisibleText("Vietnam");

Assert.assertEquals(select.getFirstSelectedOption().getText(),
"Vietnam");

driver.findElement(By.xpath("//button[text()='Search']")).click();

List<WebElement> listItems =
driver.findElements(By.xpath("//div[@class='p-1']/h4"));
Assert.assertEquals(listItems.size(), 39);
int i = 1;
for (WebElement item : listItems) {
System.out.println("Store name "+ i+ ": " + item.getText());
i++;
}
}
@Test
public void TC_03_Applitool() {
driver.get("https://applitools.com/automating-tests-chrome-devtools-
recorder-webinar/");

driver.findElement(By.id("Email")).sendKeys("[email protected]");
driver.findElement(By.cssSelector("div.mktoCheckboxList>input")).click();

driver.findElement(By.id("FirstName")).sendKeys("Janna");
driver.findElement(By.id("LastName")).sendKeys("paul");

select = new Select(driver.findElement(By.id("Person_Role__c")));


sleepInSecond(3);
select.selectByVisibleText("Consultant");
Assert.assertEquals(select.getFirstSelectedOption().getText(),
"Consultant");

driver.findElement(By.id("Company")).sendKeys("Testing");

select = new Select(driver.findElement(By.id("Test_Framework__c")));


sleepInSecond(3);
select.selectByVisibleText("Cypress");
Assert.assertEquals(select.getFirstSelectedOption().getText(),
"Cypress");

select = new
Select(driver.findElement(By.id("Self_Report_Country__c")));
sleepInSecond(3);
select.selectByVisibleText("United Kingdom");
Assert.assertEquals(select.getFirstSelectedOption().getText(), "United
Kingdom");
}
public void sleepInSecond(long time) {
try {
Thread.sleep(time*1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
@AfterClass
public void afterClass() {
driver.quit();
}
}

You might also like