• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Артём Кошелев "Тестирование фронтенда с HtmlElements: разработка быстрее, поддержка – проще"
 

Артём Кошелев "Тестирование фронтенда с HtmlElements: разработка быстрее, поддержка – проще"

on

  • 1,646 views

Пишете много тестов с использованием WebDriver? Активно используете паттерн PageObject? Спорим, у вас есть небольшая ...

Пишете много тестов с использованием WebDriver? Активно используете паттерн PageObject? Спорим, у вас есть небольшая обёрточка для WebElement’ов и парочка утилитных классов для более удобной работы с ними? Не изобретайте велосипед! Я расскажу вам об открытом решении, в котором уже есть «всё что нужно, чтобы жить дружно».

Statistics

Views

Total Views
1,646
Views on SlideShare
541
Embed Views
1,105

Actions

Likes
0
Downloads
2
Comments
0

7 Embeds 1,105

http://tech.yandex.ru 680
http://events.yandex.ru 411
https://tech.yandex.ru 8
http://events.lynx.yandex.ru 2
http://tech.osym.serpens.yandex.ru 2
http://tech.maxcold.serpens.yandex.ru 1
http://news.google.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Артём Кошелев "Тестирование фронтенда с HtmlElements: разработка быстрее, поддержка – проще" Артём Кошелев "Тестирование фронтенда с HtmlElements: разработка быстрее, поддержка – проще" Presentation Transcript

    • Front-end test automationwith HtmlElements -faster development,easier support Artem Koshelev QA Team Lead 1
    • Artem KoshelevQA Team Leadartkoshelev@yandex-team.rutwitter: @art_koshelev 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • public class HomePageTest { ! @Test ! public void testSearchResults() { ! ! WebDriver driver = new FirefoxDriver(); ! ! driver.get(“http://market.yandex.ru/”); ! ! driver.findElement(By.css(“input#search-input”)) ! ! ! .sendKeys(“чикипибарум”); ! ! driver.findElement(By.css(“td.b-search__button”)) ! ! ! .click(); ! ! assertThat(“Не найдено что ничего не найдено”, ! ! driver.findElement(By.css(“p.no-found”)).getText(), ! ! is(“Заданным условиям не соответствует ни один товар”)); ! }13
    • public class HomePageTest { ! @Test ! public void testSearchResults() { ! ! WebDriver driver = new FirefoxDriver(); ! ! driver.get(“http://market.yandex.ru/”); ! ! driver.findElement(By.css(“input#search-input”)) ! ! ! .sendKeys(“чикипибарум”); ! ! driver.findElement(By.css(“td.b-search__button”)) ! ! ! .click(); ! ! assertThat(“Не найдено что ничего не найдено”, ! ! driver.findElement(By.css(“p.no-found”)).getText(), ! ! is(“Заданным условиям не соответствует ни один товар”)); ! }14
    • public class HomePageTest { ! @Test ! public void testSearchResults() { ! ! WebDriver driver = new FirefoxDriver(); ! ! driver.get(“http://market.yandex.ru/”); ! ! driver.findElement(By.css(“input#search-input”)) ! ! ! .sendKeys(“чикипибарум”); ! ! driver.findElement(By.css(“td.b-search__button”)) ! ! ! .click(); ! ! assertThat(“Не найдено что ничего не найдено”, ! ! driver.findElement(By.css(“p.no-found”)).getText(), ! ! is(“Заданным условиям не соответствует ни один товар”)); ! }15
    • public class HomePageTest { ! @Test ! public void testSearchResults() { ! ! WebDriver driver = new FirefoxDriver(); ! ! driver.get(“http://market.yandex.ru/”); ! ! driver.findElement(By.css(“input#search-input”)) ! ! ! .sendKeys(“чикипибарум”); ! ! driver.findElement(By.css(“td.b-search__button”)) ! ! ! .click(); ! ! assertThat(“Не найдено что ничего не найдено”, ! ! driver.findElement(By.css(“p.no-found”)).getText(), ! ! is(“Заданным условиям не соответствует ни один товар”)); ! }16
    • public class HomePageTest { ! @Test ! public void testSearchResults() { ! ! WebDriver driver = new FirefoxDriver(); ! ! driver.get(“http://market.yandex.ru/”); ! ! driver.findElement(By.css(“input#search-input”)) ! ! ! .sendKeys(“чикипибарум”); ! ! driver.findElement(By.css(“td.b-search__button”)) ! ! ! .click(); ! ! assertThat(“Не найдено что ничего не найдено”, ! ! driver.findElement(By.css(“p.no-found”)).getText(), ! ! is(“Заданным условиям не соответствует ни один товар”)); ! }17
    • public class HomePageTest { ! @Test ! public void testSearchResults() { ! ! WebDriver driver = new FirefoxDriver(); ! ! driver.get(“http://market.yandex.ru/”); ! ! driver.findElement(By.css(“input#search-input”)) ! ! ! .sendKeys(“чикипибарум”); ! ! driver.findElement(By.css(“td.b-search__button”)) ! ! ! .click(); ! ! assertThat(“Не найдено что ничего не найдено”, ! ! driver.findElement(By.css(“p.no-found”)).getText(), ! ! is(“Заданным условиям не соответствует ни один товар”)); ! }18
    • 19
    • 20
    • 21
    • 22
    • 23
    • public class HomePage extends PageObject { ! private WebDriver driver; ! @FindBy(css = “input#search-input”) ! private WebElement searchInput; ! @FindBy(css = “td.b-search__button”) ! private WebElement searchButton; ! public HomePage(WebDriver driver) { ! ! return PageFactory.initElements(driver, this.class); ! } ……24
    • public class HomePage extends PageObject { ! private WebDriver driver; ! @FindBy(css = “input#search-input”) ! private WebElement searchInput; ! @FindBy(css = “td.b-search__button”) ! private WebElement searchButton; ! public HomePage(WebDriver driver) { ! ! return PageFactory.initElements(driver, this.class); ! } ……25
    • public class HomePage extends PageObject { ! private WebDriver driver; ! @FindBy(css = “input#search-input”) ! private WebElement searchInput; ! @FindBy(css = “td.b-search__button”) ! private WebElement searchButton; ! public HomePage(WebDriver driver) { ! ! return PageFactory.initElements(driver, this.class); ! } ……26
    • public class HomePage extends PageObject { ! private WebDriver driver; ! @FindBy(css = “input#search-input”) ! private WebElement searchInput; ! @FindBy(css = “td.b-search__button”) ! private WebElement searchButton; ! public HomePage(WebDriver driver) { ! ! return PageFactory.initElements(driver, this.class); ! } ……27
    • public class HomePage extends PageObject { ! …… ! public SearchResultsPage lookFor(String item) { ! ! searchInput.type(item); ! ! searchButton.click(); ! ! return new SearchResultsPage(driver); ! } ! public CatalogModelsPage clickOnElectronicLink() { ! ! electronikLink.click(); ! ! return new CatalogModelsPage(driver); ! } ……!28
    • public class HomePage extends PageObject { ! …… ! public SearchResultsPage lookFor(String item) { ! ! searchInput.type(item); ! ! searchButton.click(); ! ! return new SearchResultsPage(driver); ! } ! public CatalogModelsPage clickOnElectronicLink() { ! ! electronikLink.click(); ! ! return new CatalogModelsPage(driver); ! } ……!29
    • public class HomePage extends PageObject { ! …… ! public SearchResultsPage lookFor(String item) { ! ! searchInput.type(item); ! ! searchButton.click(); ! ! return new SearchResultsPage(driver); ! } ! public CatalogModelsPage clickOnElectronicLink() { ! ! electronikLink.click(); ! ! return new CatalogModelsPage(driver); ! } ……!30
    • HomePage onHomePage; SearchResultsPage onResultsPage; @Test public void canSearch() { ! onHomePage = new HomePage(driver).open(); ! onResultsPage = onHomePage.lookFor(“чикипибарум”); assertThat(onResultsPage.errorMessage(), ! ! ! is(“Заданным условиям не соответствует ни один товар.”)); }31
    • HomePage onHomePage; SearchResultsPage onResultsPage; @Test public void canSearch() { ! onHomePage = new HomePage(driver).open(); ! onResultsPage = onHomePage.lookFor(“чикипибарум”); assertThat(onResultsPage.errorMessage(), ! ! ! is(“Заданным условиям не соответствует ни один товар.”)); }32
    • HomePage onHomePage; SearchResultsPage onResultsPage; @Test public void canSearch() { ! onHomePage = new HomePage(driver).open(); ! onResultsPage = onHomePage.lookFor(“чикипибарум”); assertThat(onResultsPage.errorMessage(), ! ! ! is(“Заданным условиям не соответствует ни один товар.”)); }33
    • 34
    • 35
    • 36
    • UserSteps user; @Test public void canSearch() { user.onHomePage(); user.looksFor(“чикипибарум”); user.shouldSeeErrorMessage(); }37
    • 38
    • 39
    • public class HomePage extends PageObject { ! @FindBy(css = “input#search-input”) ! private WebElement searchInput; ! @FindBy(css = “td.b-search__button”) ! private WebElement searchButton;40
    • public class HomePage extends PageObject { ! @FindBy(css = “input#search-input”) ! private WebElement searchInput; ! @FindBy(css = “td.b-search__button”) ! private WebElement searchButton;41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • @Block(@FindBy(…)) public class SearchArrow extends HtmlElement { ! ! @FindBy(…) ! ! private WebElement searchInput; ! ! @FindBy(…) ! ! private WebElement searchButton; }62
    • @Block(@FindBy(…)) public class SearchArrow extends HtmlElement { ! ! @FindBy(…) ! ! private WebElement searchInput; ! ! @FindBy(…) ! ! private WebElement searchButton; }63
    • @Block(@FindBy(…)) public class SearchArrow extends HtmlElement { ! ! @FindBy(…) ! ! private WebElement searchInput; ! ! @FindBy(…) ! ! private WebElement searchButton; }64
    • @Block(@FindBy(…)) public class SearchArrow extends HtmlElement { ! ! @FindBy(…) ! ! private WebElement searchInput; ! ! @FindBy(…) ! ! private WebElement searchButton; }65
    • 66
    • @Block(@FindBy(…)) public class SearchBlock extends HtmlElement { ! ! private SearchArrow arrow; ! ! private SearchTabs tabs; }67
    • public class HomePage extends PageObject { ! ! public SearchBlock searchBlock; }68
    • public class HomePage extends PageObject { @FindBy(xpath = “//another_locator”) ! ! public SearchBlock arrow; }69
    • 70
    • @Block(@FindBy(…)) public class SearchArrow extends HtmlElement { ! ! @FindBy(…) ! ! private WebElement searchInput; ! ! @FindBy(…) ! ! private WebElement searchButton; }71
    • @Block(@FindBy(…)) public class SearchArrow extends HtmlElement { ! ! @FindBy(…) ! ! private TextInput searchInput; ! ! @FindBy(…) ! ! private Button searchButton; }72
    • 73
    • 74
    • 75
    • public class Form extends TypifiedElement { public void fill(Map<String, Object> data) {...} public <T> void fill(T bean, Converter beanToMapConverter) {...} ... }76
    • public class Table extends TypifiedElement { public List<WebElement> getHeadings() {} public List<List<WebElement>> getRows() {} public List<List<WebElement>> getColumns() {} }77
    • public class Link extends TypifiedElement { ! public Link(WebElement wrappedElement) { ! ! super(wrappedElement) ! } ...... }78
    • public class Link extends TypifiedElement { ...... ! public void click() {…} ! public String getReference() {…} ! public String getText(){…} }79
    • 80
    • assertThat(actual, Matcher);81
    • assertThat(event, is(“Я.Субботник в Риге”)); assertThat(today, isSameDayOfTheWeek(31_jan_2009)); assertThat(attendies, not(lessThan(100)));82
    • assertThat(seasonsControlForm, exists()); assertThat(seasonsControlForm, hasText(«Seasons shift setup»)); assertThat(enableSeasonsShift, isSelected()); assertThat(currentSeason, hasSelectedOption( hasText(«Spring»)));83
    • assertThat(seasonsControlForm, exists()); assertThat(seasonsControlForm, hasText(«Seasons shift setup»)); assertThat(enableSeasonsShift, isSelected()); assertThat(currentSeason, hasSelectedOption( hasText(«Spring»)));84
    • assertThat(seasonsControlForm, exists()); assertThat(seasonsControlForm, hasText(«Seasons shift setup»)); assertThat(enableSeasonsShift, isSelected()); assertThat(currentSeason, hasSelectedOption( hasText(«Spring»)));85
    • assertThat(seasonsControlForm, exists()); assertThat(seasonsControlForm, hasText(«Seasons shift setup»)); assertThat(enableSeasonsShift, isSelected()); assertThat(currentSeason, hasSelectedOption( hasText(«Spring»)));86
    • assertThat(element, should(exists()). whileWaitingUntil(timeout)); assertThat(element, should(exists()). after(pageRefresh(driver)); assertThat(humanRace, should(not(exists())). inCase(zombieApocalypse)); assertThat(chuckNorris, should(exists()). inCase(zombieApocalypse));87
    • assertThat(element, should(exists()). whileWaitingUntil(timeout)); assertThat(element, should(exists()). after(pageRefresh(driver)); assertThat(humanRace, should(not(exists())). inCase(zombieApocalypse)); assertThat(chuckNorris, should(exists()). inCase(zombieApocalypse));88
    • assertThat(element, should(exists()). whileWaitingUntil(timeout)); assertThat(element, should(exists()). after(pageRefresh(driver)); assertThat(humanRace, should(not(exists())). inCase(zombieApocalypse)); assertThat(chuckNorris, should(exists()). inCase(zombieApocalypse));89
    • assertThat(element, should(exists()). whileWaitingUntil(timeout)); assertThat(element, should(exists()). after(pageRefresh(driver)); assertThat(humanRace, should(not(exists())). inCase(zombieApocalypse)); assertThat(chuckNorris, should(exists()). inCase(zombieApocalypse));90
    • assertThat(element, should(exists()). whileWaitingUntil(timeout)); assertThat(element, should(exists()). after(pageRefresh(driver)); assertThat(humanRace, should(not(exists())). inCase(zombieApocalypse)); assertThat(chuckNorris, should(exists()). inCase(zombieApocalypse));91
    • assertThat(element, should(exists()). whileWaitingUntil(timeout)); assertThat(element, should(exists()). after(pageRefresh(driver)); assertThat(humanRace, should(not(exists())). inCase(zombieApocalypse)); assertThat(chuckNorris, should(exists()). inCase(zombieApocalypse));92
    • public void shouldSeeSuggest(Matcher mchr) { assertThat( onSearchPage().getSuggest(), mchr); } @Test public void popularSuggests() { user.opensSearchPage(); user.typesInSearch(«riga»); user.shouldSeeSuggest( everyItem(hasText(startsWith(«riga»)))); user.shouldSeeSuggest(93 hasItem(hasText(«riga weather»)));
    • public void shouldSeeSuggest(Matcher mchr) { assertThat( onSearchPage().getSuggest(), mchr); } @Test public void popularSuggests() { user.opensSearchPage(); user.typesInSearch(«riga»); user.shouldSeeSuggest( everyItem(hasText(startsWith(«riga»)))); user.shouldSeeSuggest(94 hasItem(hasText(«riga weather»)));
    • public void shouldSeeSuggest(Matcher mchr) { assertThat( onSearchPage().getSuggest(), mchr); } @Test public void popularSuggests() { user.opensSearchPage(); user.typesInSearch(«riga»); user.shouldSeeSuggest( everyItem(hasText(startsWith(«riga»)))); user.shouldSeeSuggest(95 hasItem(hasText(«riga weather»)));
    • public void shouldSeeSuggest(Matcher mchr) { assertThat( onSearchPage().getSuggest(), mchr); } @Test public void popularSuggests() { user.opensSearchPage(); user.typesInSearch(«riga»); user.shouldSeeSuggest( everyItem(hasText(startsWith(«riga»)))); user.shouldSeeSuggest(96 hasItem(hasText(«riga weather»)));
    • public void shouldSeeSuggest(Matcher mchr) { assertThat( onSearchPage().getSuggest(), mchr); } @Test public void popularSuggests() { user.opensSearchPage(); user.typesInSearch(«riga»); user.shouldSeeSuggest( everyItem(hasText(startsWith(«riga»)))); user.shouldSeeSuggest(97 hasItem(hasText(«riga weather»)));
    • 98
    • <dependency> <groupId> ru.yandex.qatools.htmlelements </groupId> <artifactId> htmlelements-java </artifactId> <version>1.9</version> </dependency>99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • http://bit.ly/htmlelements http://bit.ly/yqahegg qa-tools@yandex-team.ru106
    • Artem KoshelevQA Team Leadartkoshelev@yandex-team.rutwitter: @art_koshelev 107