SHARE
TWEET

Untitled

a guest Dec 3rd, 2019 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. package com.test.test;
  3.  
  4. import static org.testng.Assert.assertEquals;
  5.  
  6. import java.util.concurrent.TimeUnit;
  7. import org.openqa.selenium.By;
  8. import org.openqa.selenium.WebDriver;
  9. import org.openqa.selenium.WebElement;
  10. import org.openqa.selenium.chrome.ChromeDriver;
  11. import org.openqa.selenium.support.ui.Select;
  12. import org.testng.annotations.AfterClass;
  13. import org.testng.annotations.AfterMethod;
  14. import org.testng.annotations.BeforeClass;
  15. import org.testng.annotations.BeforeMethod;
  16. import org.testng.annotations.Test;
  17.  
  18. public class NewTest {
  19.     WebDriver driver;
  20.  
  21.     @BeforeClass
  22.     public void testSetup() {
  23.         System.setProperty("webdriver.chrome.driver", "D:\\JAVA\\chromedriver.exe");
  24.         driver = new ChromeDriver();
  25.         driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
  26.         driver.manage().window().maximize();
  27.    
  28.  
  29.     }
  30.  
  31.     @BeforeMethod
  32.     public void openBrowser() {
  33.        
  34.         driver.get("https://www.facebook.com/");
  35.         System.out.println("We are currently on the following URL" + driver.getCurrentUrl());
  36.         WebElement textDemo = driver.findElement(By.xpath("//*[text()='Tạo tài khoản mới']"));
  37.         if (textDemo!=null)
  38.         {
  39.             System.out.println("Element found using text");
  40.             textDemo.click();
  41.         }
  42.  
  43.     }
  44.  
  45.     @Test(description = "This method validates the sign up with name is error")
  46.     public void signUp() {
  47.         driver.findElement(By.name("lastname")).sendKeys("abcds");
  48.         driver.findElement(By.name("firstname")).sendKeys("Sadhvi Singh");
  49.         driver.findElement(By.name("reg_email__")).sendKeys("sadhvisingh9049+1@gmail.com");
  50.         driver.findElement(By.name("reg_email_confirmation__")).sendKeys("sadhvisingh9049+1@gmail.com");
  51.         driver.findElement(By.name("reg_passwd__")).sendKeys("BrowserStack123*");
  52.  
  53.         // chọn value cho combobox
  54.         WebElement testDropDown = driver.findElement(By.name("birthday_day"));
  55.         Select day = new Select(testDropDown);
  56.         day.selectByValue("2");
  57.         testDropDown = driver.findElement(By.name("birthday_month"));
  58.         Select month = new Select(testDropDown);
  59.         month.selectByValue("2");
  60.         testDropDown = driver.findElement(By.name("birthday_year"));
  61.         Select year = new Select(testDropDown);
  62.         year.selectByValue("1994");
  63.  
  64.         int a = driver.findElements(By.xpath("//input [@name='sex']")).size();
  65.        
  66.         // chọn value cho radio
  67.         for (int i = 1; i <= a; i++) {
  68.            
  69.             driver.findElements(By.xpath("//input[@name='sex']")).get(1).click();
  70.         }
  71.         driver.findElement(By.name("websubmit")).click();
  72.        
  73.         // chờ click xong
  74.         driver.manage().timeouts().implicitlyWait(1, TimeUnit.MINUTES);
  75.        
  76.        
  77.         WebElement text = driver.findElement(By.id("reg_error_inner"));
  78.         // kiểm tra element error có xuất hiện không
  79.         assertEquals(text.isDisplayed(),true);
  80.  
  81.     }
  82.  
  83.     @AfterMethod
  84.     public void postSignUp() {
  85.         System.out.println(driver.getCurrentUrl());
  86.  
  87.     }
  88.  
  89.     @AfterClass
  90.     public void afterClass() {
  91.         // driver.quit();
  92.     }
  93. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top