Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
552
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. package AssignmentJUNIT.TestCase1;
  2.  
  3. import java.util.logging.FileHandler;
  4. import java.util.logging.Logger;
  5. import java.util.logging.SimpleFormatter;
  6.  
  7. import org.junit.After;
  8. import org.junit.AfterClass;
  9. import org.junit.Before;
  10. import org.junit.BeforeClass;
  11. import org.junit.Test;
  12. import org.junit.Assert;
  13. import org.openqa.selenium.By;
  14. import org.openqa.selenium.WebDriver;
  15. import org.openqa.selenium.firefox.FirefoxDriver;
  16. import org.openqa.selenium.support.ui.ExpectedConditions;
  17. import org.openqa.selenium.support.ui.WebDriverWait;
  18. import junit.framework.TestCase;
  19.  
  20.  
  21. public class TestCase1 {
  22. private static WebDriver driver;
  23. private static WebDriverWait wait;
  24. private static String baseURL = "https://www.br.se/";
  25. private static String expected = "";
  26. private static String actual = "";
  27. public static Logger LOG;
  28. static FileHandler fh;
  29.  
  30. @BeforeClass
  31. public static void SetupOnce(){
  32. driver = new FirefoxDriver();
  33. wait = new WebDriverWait(driver, 3);
  34. LOG = Logger.getLogger(TestCase1.class.getName());
  35. try{
  36. fh = new FileHandler("C:\\Users\\Christian Ström\\workspace\\TestautoExercise2\\TestCase1\\log\\log.log");
  37. }catch(Exception e) {
  38. e.printStackTrace();
  39. }
  40. LOG.addHandler(fh);
  41. SimpleFormatter formatter = new SimpleFormatter();
  42. fh.setFormatter(formatter);
  43. System.out.println("@BeforeClass setupOnce()");
  44. }
  45. @Before
  46. public void resetData(){
  47. driver.navigate().to(baseURL);
  48. System.out.println("@Before resetData()");
  49. expected = "";
  50. actual = "";
  51. }
  52. @Test
  53. public void testLogin(){
  54. //Prepare
  55. expected = "Profile";
  56. LOG.info("Inputting correct login info, expecting to reach profile page");
  57. String passwordId = "j_password";
  58. String userNameID = "j_username";
  59. String loginButtonHeaderXpath = ".//*[@id='iconbar']/div[1]/a[1]/div";
  60. String loginButtonXpath = ".//*[@id='loginForm']/div[3]/button";
  61. String changePasswordXpath = ".//*[@id='content']/div/a[1]";
  62.  
  63. driver.findElement(By.xpath(loginButtonHeaderXpath)).click();
  64. wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(loginButtonXpath)));
  65. driver.findElement(By.id(userNameID)).sendKeys("p1092391@mvrht.com");
  66. driver.findElement(By.id(passwordId)).sendKeys("test123");
  67. driver.findElement(By.xpath(loginButtonXpath)).click();
  68. wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(changePasswordXpath)));
  69.  
  70. actual = driver.getTitle();
  71.  
  72. LOG.info("Actual: " + actual);
  73. Assert.assertTrue("Login Fail", driver.getTitle().contains(expected));
  74. }
  75. @After
  76. public void tearDown(){
  77. System.out.println("@After tearDown()");
  78. }
  79. @AfterClass
  80. public static void tearDownOnce(){
  81. System.out.println("@AfterClass tearDownOnce()");
  82. driver.close();
  83. try{
  84. Thread.sleep(3000);
  85. }catch(InterruptedException e){
  86. System.out.println(e.getStackTrace());
  87. }
  88. driver.quit();
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement