Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import org.apache.commons.io.FileUtils;
- import org.junit.*;
- import org.openqa.selenium.By;
- import org.openqa.selenium.OutputType;
- import org.openqa.selenium.TakesScreenshot;
- import org.openqa.selenium.WebDriver;
- import org.openqa.selenium.WebElement;
- import org.openqa.selenium.chrome.ChromeDriver;
- import org.openqa.selenium.chrome.ChromeOptions;
- import org.openqa.selenium.support.ui.ExpectedConditions;
- import org.openqa.selenium.support.ui.WebDriverWait;
- public class FirstAutomationTest {
- private static WebDriver driver;
- private String appURL = "http://testing-ground.scraping.pro/login";
- private String USER = "admin";
- private String PASS = "12345";
- private String USER_ID = "usr";
- private String USER_PWD = "pwd";
- private By BUTTON_SUBMIT = By.xpath("//input[@value='Login']");
- private By WELCOME_MESSAGE = By.xpath("//div[@id='case_login']/h3");
- @BeforeClass
- public static void settingUPChrome() {// Setting chromedriver driver
- // Call chromedriver.
- System.setProperty("webdriver.chrome.driver", "/home/steve/Documents/CURSOS/CURSOS_EXTERNO/swd/chromedriver");
- ChromeOptions options = new ChromeOptions();
- //Disable barInfo
- options.addArguments("disable-infobars");
- driver = new ChromeDriver(options);
- }
- @Test
- public void login(){
- driver.navigate().to(appURL);
- WebElement userName_editbox = driver.findElement(By.id(USER_ID));
- WebElement password_editbox = driver.findElement(By.id(USER_PWD));
- WebElement submit_button = driver.findElement(BUTTON_SUBMIT);
- userName_editbox.sendKeys(USER);
- password_editbox.sendKeys(PASS);
- submit_button.click();
- }
- @Test
- public void verifyUserIsLoginCorrectly(){
- WebDriverWait wait = new WebDriverWait(driver, 30000);
- WebElement element = wait.until(ExpectedConditions.elementToBeClickable(WELCOME_MESSAGE));
- String aux = driver.findElement(WELCOME_MESSAGE).getText();
- Assert.assertEquals(aux,"WELCOME :)");
- }
- @After
- public void saveScreenshott () throws IOException { //Saves the screenshot
- File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
- FileUtils.copyFile(scrFile, new File("Screenshot.png"));
- }
- @AfterClass
- public static void closeBrowser() {
- driver.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement