Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.test.test;
- import static org.testng.Assert.assertEquals;
- import java.util.concurrent.TimeUnit;
- import org.openqa.selenium.By;
- import org.openqa.selenium.WebDriver;
- import org.openqa.selenium.WebElement;
- import org.openqa.selenium.chrome.ChromeDriver;
- import org.openqa.selenium.support.ui.Select;
- import org.testng.annotations.AfterClass;
- import org.testng.annotations.AfterMethod;
- import org.testng.annotations.BeforeClass;
- import org.testng.annotations.BeforeMethod;
- import org.testng.annotations.Test;
- public class NewTest {
- WebDriver driver;
- @BeforeClass
- public void testSetup() {
- System.setProperty("webdriver.chrome.driver", "D:\\JAVA\\chromedriver.exe");
- driver = new ChromeDriver();
- driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
- driver.manage().window().maximize();
- }
- @BeforeMethod
- public void openBrowser() {
- driver.get("https://www.facebook.com/");
- System.out.println("We are currently on the following URL" + driver.getCurrentUrl());
- WebElement textDemo = driver.findElement(By.xpath("//*[text()='Tạo tài khoản mới']"));
- if (textDemo!=null)
- {
- System.out.println("Element found using text");
- textDemo.click();
- }
- }
- @Test(description = "This method validates the sign up with name is error")
- public void signUp() {
- driver.findElement(By.name("lastname")).sendKeys("abcds");
- driver.findElement(By.name("firstname")).sendKeys("Sadhvi Singh");
- driver.findElement(By.name("reg_email__")).sendKeys("sadhvisingh9049+1@gmail.com");
- driver.findElement(By.name("reg_email_confirmation__")).sendKeys("sadhvisingh9049+1@gmail.com");
- driver.findElement(By.name("reg_passwd__")).sendKeys("BrowserStack123*");
- // chọn value cho combobox
- WebElement testDropDown = driver.findElement(By.name("birthday_day"));
- Select day = new Select(testDropDown);
- day.selectByValue("2");
- testDropDown = driver.findElement(By.name("birthday_month"));
- Select month = new Select(testDropDown);
- month.selectByValue("2");
- testDropDown = driver.findElement(By.name("birthday_year"));
- Select year = new Select(testDropDown);
- year.selectByValue("1994");
- int a = driver.findElements(By.xpath("//input [@name='sex']")).size();
- // chọn value cho radio
- for (int i = 1; i <= a; i++) {
- driver.findElements(By.xpath("//input[@name='sex']")).get(1).click();
- }
- driver.findElement(By.name("websubmit")).click();
- // chờ click xong
- driver.manage().timeouts().implicitlyWait(1, TimeUnit.MINUTES);
- WebElement text = driver.findElement(By.id("reg_error_inner"));
- // kiểm tra element error có xuất hiện không
- assertEquals(text.isDisplayed(),true);
- }
- @AfterMethod
- public void postSignUp() {
- System.out.println(driver.getCurrentUrl());
- }
- @AfterClass
- public void afterClass() {
- // driver.quit();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement