Advertisement
Guest User

Untitled

a guest
Jul 5th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.42 KB | None | 0 0
  1. import java.io.*;
  2.  
  3. import org.apache.commons.io.FileUtils;
  4. import org.junit.*;
  5. import org.openqa.selenium.By;
  6. import org.openqa.selenium.OutputType;
  7. import org.openqa.selenium.TakesScreenshot;
  8. import org.openqa.selenium.WebDriver;
  9. import org.openqa.selenium.WebElement;
  10. import org.openqa.selenium.chrome.ChromeDriver;
  11. import org.openqa.selenium.chrome.ChromeOptions;
  12. import org.openqa.selenium.support.ui.ExpectedConditions;
  13. import org.openqa.selenium.support.ui.WebDriverWait;
  14.  
  15. public class FirstAutomationTest {
  16.  
  17.     private static WebDriver driver;
  18.     private String appURL = "http://testing-ground.scraping.pro/login";
  19.     private String USER = "admin";
  20.     private String PASS = "12345";
  21.     private String USER_ID = "usr";
  22.     private String USER_PWD = "pwd";
  23.     private By BUTTON_SUBMIT = By.xpath("//input[@value='Login']");
  24.     private By WELCOME_MESSAGE = By.xpath("//div[@id='case_login']/h3");
  25.  
  26.  
  27.     @BeforeClass
  28.     public static void settingUPChrome() {// Setting chromedriver driver
  29.         // Call chromedriver.
  30.         System.setProperty("webdriver.chrome.driver", "/home/steve/Documents/CURSOS/CURSOS_EXTERNO/swd/chromedriver");
  31.         ChromeOptions options = new ChromeOptions();
  32.         //Disable barInfo
  33.         options.addArguments("disable-infobars");
  34.         driver = new ChromeDriver(options);
  35.     }
  36.  
  37.     @Test
  38.     public void login(){
  39.         driver.navigate().to(appURL);
  40.         WebElement userName_editbox = driver.findElement(By.id(USER_ID));
  41.         WebElement password_editbox = driver.findElement(By.id(USER_PWD));
  42.         WebElement submit_button = driver.findElement(BUTTON_SUBMIT);
  43.         userName_editbox.sendKeys(USER);
  44.         password_editbox.sendKeys(PASS);
  45.         submit_button.click();
  46.    }
  47.  
  48.     @Test
  49.     public void verifyUserIsLoginCorrectly(){
  50.         WebDriverWait wait = new WebDriverWait(driver, 30000);
  51.         WebElement element = wait.until(ExpectedConditions.elementToBeClickable(WELCOME_MESSAGE));
  52.         String aux = driver.findElement(WELCOME_MESSAGE).getText();
  53.         Assert.assertEquals(aux,"WELCOME :)");
  54.     }
  55.  
  56.     @After
  57.     public void saveScreenshott () throws IOException { //Saves the screenshot
  58.         File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
  59.         FileUtils.copyFile(scrFile, new File("Screenshot.png"));
  60.     }
  61.  
  62.     @AfterClass
  63.     public static void closeBrowser() {
  64.         driver.close();
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement