ݺߣ

ݺߣShare a Scribd company logo
Делаем тесты лучше
Юлия Ашаева
Автотесты от Selenium IDE
Плюсы
Быстрый старт
Просто получить
Минусы
Нечитаемо
Хрупкие (зависят
от верстки)
Тяжело
поддерживать
Приложение 
Test data

Application driver

Test logic
Domain Specific Language
Test logic
DSL driver
Application driver
Selenium plugin for Intellij IDEA
Settings → Plugins →Browse repositories
Look for Selenium plugin
http://perfect-test.com/index.php/ru/instruments-rus-menu/15-selenium-plugin-rus
public abstract class Page {
protected WebDriver driver;
public Page(WebDriver driver) {
this.driver = driver;
}
public abstract void open();
protected void type(WebElement webElement, String text) {
webElement.clear();
webElement.sendKeys(text);
}
public boolean isElementPresent(WebElement element) {
try {
element.isDisplayed();
return true;
} catch (NoSuchElementException e) {
return false;
}
}
}
public class LoginPage extends Page {
@FindBy(className="login")
public WebElement linkSignIn;
@FindBy(id="username")
WebElement fieldUsername;
@FindBy(id="password")
WebElement fieldPassword;
@FindBy(name="login")
WebElement buttonLogin;
public LoginPage(WebDriver driver) {
super(driver);
}
public HomePage loginAs(UserData user) {
linkSignIn.click();
type(fieldUsername, user.name);
type(fieldPassword, user.password);
buttonLogin.click();
return PageFactory.initElements(driver, HomePage.class);
}
@Override
public void open() {
driver.get(ConfigProperties.getProperty("login.url"));
}
}
public class BasicTestCase {
protected static WebDriver driver;
protected WebDriver getWebDriver() {
if (driver == null) {
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(
Long.parseLong(ConfigProperties.getProperty("imp.wait")),
TimeUnit.SECONDS);
}
return driver;
}
@AfterTest
public void tearDown() throws Exception {
driver.quit();
}
}
public class TestLogin extends BasicTestCase{
public final static UserData user = new UserData("jashaeva", "helloWorld");
private HomePage homePage =
PageFactory.initElements(getWebDriver(), HomePage.class);
private LoginPage loginPage =
PageFactory.initElements(getWebDriver(), LoginPage.class);
@Test
public void testLogin() throws Exception {
loginPage.open();
homePage = loginPage.loginAs(user);
assertTrue(homePage.isLoggedIn());
homePage.logout();
assertTrue(homePage.isLoggedOut());
}
}
DSL
Что дальше?
PageElement
Form
Checkbox
Button
Select

More Related Content

Стажировка 2016-08-04 02 Юлия Ашаева. Делаем тесты лучше

  • 2. Автотесты от Selenium IDE Плюсы Быстрый старт Просто получить Минусы Нечитаемо Хрупкие (зависят от верстки) Тяжело поддерживать
  • 4. Domain Specific Language Test logic DSL driver Application driver
  • 5. Selenium plugin for Intellij IDEA Settings → Plugins →Browse repositories Look for Selenium plugin http://perfect-test.com/index.php/ru/instruments-rus-menu/15-selenium-plugin-rus
  • 6. public abstract class Page { protected WebDriver driver; public Page(WebDriver driver) { this.driver = driver; } public abstract void open(); protected void type(WebElement webElement, String text) { webElement.clear(); webElement.sendKeys(text); } public boolean isElementPresent(WebElement element) { try { element.isDisplayed(); return true; } catch (NoSuchElementException e) { return false; } } }
  • 7. public class LoginPage extends Page { @FindBy(className="login") public WebElement linkSignIn; @FindBy(id="username") WebElement fieldUsername; @FindBy(id="password") WebElement fieldPassword; @FindBy(name="login") WebElement buttonLogin; public LoginPage(WebDriver driver) { super(driver); } public HomePage loginAs(UserData user) { linkSignIn.click(); type(fieldUsername, user.name); type(fieldPassword, user.password); buttonLogin.click(); return PageFactory.initElements(driver, HomePage.class); } @Override public void open() { driver.get(ConfigProperties.getProperty("login.url")); } }
  • 8. public class BasicTestCase { protected static WebDriver driver; protected WebDriver getWebDriver() { if (driver == null) { driver = new FirefoxDriver(); driver.manage().timeouts().implicitlyWait( Long.parseLong(ConfigProperties.getProperty("imp.wait")), TimeUnit.SECONDS); } return driver; } @AfterTest public void tearDown() throws Exception { driver.quit(); } }
  • 9. public class TestLogin extends BasicTestCase{ public final static UserData user = new UserData("jashaeva", "helloWorld"); private HomePage homePage = PageFactory.initElements(getWebDriver(), HomePage.class); private LoginPage loginPage = PageFactory.initElements(getWebDriver(), LoginPage.class); @Test public void testLogin() throws Exception { loginPage.open(); homePage = loginPage.loginAs(user); assertTrue(homePage.isLoggedIn()); homePage.logout(); assertTrue(homePage.isLoggedOut()); } }
  • 10. DSL