Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package AssignmentJUNIT.TestCase1;
- import java.util.logging.FileHandler;
- import java.util.logging.Logger;
- import java.util.logging.SimpleFormatter;
- import org.junit.After;
- import org.junit.AfterClass;
- import org.junit.Before;
- import org.junit.BeforeClass;
- import org.junit.Test;
- import org.junit.Assert;
- import org.openqa.selenium.By;
- import org.openqa.selenium.WebDriver;
- import org.openqa.selenium.firefox.FirefoxDriver;
- import org.openqa.selenium.support.ui.ExpectedConditions;
- import org.openqa.selenium.support.ui.WebDriverWait;
- import junit.framework.TestCase;
- public class TestCase1 {
- private static WebDriver driver;
- private static WebDriverWait wait;
- private static String baseURL = "https://www.br.se/";
- private static String expected = "";
- private static String actual = "";
- public static Logger LOG;
- static FileHandler fh;
- @BeforeClass
- public static void SetupOnce(){
- driver = new FirefoxDriver();
- wait = new WebDriverWait(driver, 3);
- LOG = Logger.getLogger(TestCase1.class.getName());
- try{
- fh = new FileHandler("C:\\Users\\Christian Ström\\workspace\\TestautoExercise2\\TestCase1\\log\\log.log");
- }catch(Exception e) {
- e.printStackTrace();
- }
- LOG.addHandler(fh);
- SimpleFormatter formatter = new SimpleFormatter();
- fh.setFormatter(formatter);
- System.out.println("@BeforeClass setupOnce()");
- }
- @Before
- public void resetData(){
- driver.navigate().to(baseURL);
- System.out.println("@Before resetData()");
- expected = "";
- actual = "";
- }
- @Test
- public void testLogin(){
- //Prepare
- expected = "Profile";
- LOG.info("Inputting correct login info, expecting to reach profile page");
- String passwordId = "j_password";
- String userNameID = "j_username";
- String loginButtonHeaderXpath = ".//*[@id='iconbar']/div[1]/a[1]/div";
- String loginButtonXpath = ".//*[@id='loginForm']/div[3]/button";
- String changePasswordXpath = ".//*[@id='content']/div/a[1]";
- driver.findElement(By.xpath(loginButtonHeaderXpath)).click();
- wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(loginButtonXpath)));
- driver.findElement(By.id(userNameID)).sendKeys("[email protected]");
- driver.findElement(By.id(passwordId)).sendKeys("test123");
- driver.findElement(By.xpath(loginButtonXpath)).click();
- wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(changePasswordXpath)));
- actual = driver.getTitle();
- LOG.info("Actual: " + actual);
- Assert.assertTrue("Login Fail", driver.getTitle().contains(expected));
- }
- @After
- public void tearDown(){
- System.out.println("@After tearDown()");
- }
- @AfterClass
- public static void tearDownOnce(){
- System.out.println("@AfterClass tearDownOnce()");
- driver.close();
- try{
- Thread.sleep(3000);
- }catch(InterruptedException e){
- System.out.println(e.getStackTrace());
- }
- driver.quit();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment