Guest User

Untitled

a guest
Mar 20th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. private LoginPage loginPage;
  2. private DashboardPage homePage;
  3.  
  4. @Before
  5. public void setUp() throws Exception {
  6.  
  7. loginPage =new LoginPage(driver);
  8. homePage = new DashboardPage (driver);
  9.  
  10. }
  11.  
  12. @After
  13. public void tearDown() throws Exception {
  14. }
  15.  
  16. @Test
  17. public void test() {
  18.  
  19. loginPage.load();
  20. loginPage.login();
  21. homePage.getWelcomeMessage();
  22. String actualWelcome=homePage.getWelcomeMessage();
  23. assertEquals("Welcome Admin",actualWelcome);
  24.  
  25. homePage.logout();
  26.  
  27. }
  28.  
  29. public LoginPage(WebDriver driver) {
  30. super(driver);
  31.  
  32. }
  33.  
  34. public void login() {
  35. // TODO Auto-generated method stub
  36. driver.findElement(By.id("txtUsername")).sendKeys("admin");;
  37. driver.findElement(By.id("txtPassword")).sendKeys("Password");;
  38. driver.findElement(By.id("btnLogin")).click();;
  39. }
  40.  
  41. public DashboardPage(WebDriver driver) {
  42. super(driver);
  43. // TODO Auto-generated constructor stub
  44. }
  45.  
  46. public String getWelcomeMessage() {
  47.  
  48.  
  49. return wait.until(ExpectedConditions.presenceOfElementLocated(
  50. By.id("welcome"))).getText();
  51.  
  52.  
  53. }
  54.  
  55. public void logout() {
  56.  
  57.  
  58. wait.until(ExpectedConditions.visibilityOfElementLocated(
  59. By.linkText("Logout"))).click();
  60.  
  61. }
  62.  
  63. protected WebDriver driver;
  64. protected WebDriverWait wait;
  65.  
  66.  
  67. @Before
  68. public void setUp() throws Exception {
  69. System.setProperty("webdriver.gecko.driver", "geckodriver.exe");
  70. driver = new FirefoxDriver();
  71. wait=new WebDriverWait(driver, 5);
  72. driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
  73. }
  74.  
  75. @After
  76. public void basetearDown() throws Exception {
  77. driver.quit();
Add Comment
Please, Sign In to add comment