Front-end test automationwith HtmlElements -faster development,easier support  Artem Koshelev  QA Team Lead               ...
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 FirefoxDriv...
public class HomePageTest {     ! @Test     ! public void testSearchResults() {     ! ! WebDriver driver = new FirefoxDriv...
public class HomePageTest {     ! @Test     ! public void testSearchResults() {     ! ! WebDriver driver = new FirefoxDriv...
public class HomePageTest {     ! @Test     ! public void testSearchResults() {     ! ! WebDriver driver = new FirefoxDriv...
public class HomePageTest {     ! @Test     ! public void testSearchResults() {     ! ! WebDriver driver = new FirefoxDriv...
public class HomePageTest {     ! @Test     ! public void testSearchResults() {     ! ! WebDriver driver = new FirefoxDriv...
19
20
21
22
23
public class HomePage extends PageObject {     ! private WebDriver driver;     ! @FindBy(css = “input#search-input”)     !...
public class HomePage extends PageObject {     ! private WebDriver driver;     ! @FindBy(css = “input#search-input”)     !...
public class HomePage extends PageObject {     ! private WebDriver driver;     ! @FindBy(css = “input#search-input”)     !...
public class HomePage extends PageObject {     ! private WebDriver driver;     ! @FindBy(css = “input#search-input”)     !...
public class HomePage extends PageObject {     ! ……     !   public SearchResultsPage lookFor(String item) {     !   ! sear...
public class HomePage extends PageObject {     ! ……     !   public SearchResultsPage lookFor(String item) {     !   ! sear...
public class HomePage extends PageObject {     ! ……     !   public SearchResultsPage lookFor(String item) {     !   ! sear...
HomePage onHomePage;     SearchResultsPage onResultsPage;     @Test     public void canSearch() {     ! onHomePage = new H...
HomePage onHomePage;     SearchResultsPage onResultsPage;     @Test     public void canSearch() {     ! onHomePage = new H...
HomePage onHomePage;     SearchResultsPage onResultsPage;     @Test     public void canSearch() {     ! onHomePage = new H...
34
35
36
UserSteps user;     @Test     public void canSearch() {       user.onHomePage();       user.looksFor(“чикипибарум”);      ...
38
39
public class HomePage extends PageObject {     ! @FindBy(css = “input#search-input”)     ! private WebElement searchInput;...
public class HomePage extends PageObject {     ! @FindBy(css = “input#search-input”)     ! private WebElement searchInput;...
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 search...
@Block(@FindBy(…))     public class SearchArrow extends HtmlElement {     ! ! @FindBy(…)     ! ! private WebElement search...
@Block(@FindBy(…))     public class SearchArrow extends HtmlElement {     ! ! @FindBy(…)     ! ! private WebElement search...
@Block(@FindBy(…))     public class SearchArrow extends HtmlElement {     ! ! @FindBy(…)     ! ! private WebElement search...
66
@Block(@FindBy(…))     public class SearchBlock extends HtmlElement {     ! ! private SearchArrow arrow;     ! ! private S...
public class HomePage extends PageObject {     ! ! public SearchBlock searchBlock;     }68
public class HomePage extends PageObject {         @FindBy(xpath = “//another_locator”)     ! ! public SearchBlock arrow; ...
70
@Block(@FindBy(…))     public class SearchArrow extends HtmlElement {     ! ! @FindBy(…)     ! ! private WebElement search...
@Block(@FindBy(…))     public class SearchArrow extends HtmlElement {     ! ! @FindBy(…)     ! ! private TextInput searchI...
73
74
75
public class Form extends TypifiedElement {         public void fill(Map<String, Object> data)         {...}         publi...
public class Table extends TypifiedElement {         public List<WebElement> getHeadings() {}         public List<List<Web...
public class Link extends TypifiedElement {     ! public Link(WebElement wrappedElement) {     ! ! super(wrappedElement)  ...
public class Link extends TypifiedElement {         ......     ! public void click() {…}     ! public String getReference(...
80
assertThat(actual, Matcher);81
assertThat(event, is(“Я.Субботник в Риге”));     assertThat(today,             isSameDayOfTheWeek(31_jan_2009));     asser...
assertThat(seasonsControlForm, exists());     assertThat(seasonsControlForm,           hasText(«Seasons shift setup»));   ...
assertThat(seasonsControlForm, exists());     assertThat(seasonsControlForm,           hasText(«Seasons shift setup»));   ...
assertThat(seasonsControlForm, exists());     assertThat(seasonsControlForm,           hasText(«Seasons shift setup»));   ...
assertThat(seasonsControlForm, exists());     assertThat(seasonsControlForm,           hasText(«Seasons shift setup»));   ...
assertThat(element, should(exists()).                    whileWaitingUntil(timeout));     assertThat(element, should(exist...
assertThat(element, should(exists()).                    whileWaitingUntil(timeout));     assertThat(element, should(exist...
assertThat(element, should(exists()).                    whileWaitingUntil(timeout));     assertThat(element, should(exist...
assertThat(element, should(exists()).                    whileWaitingUntil(timeout));     assertThat(element, should(exist...
assertThat(element, should(exists()).                    whileWaitingUntil(timeout));     assertThat(element, should(exist...
assertThat(element, should(exists()).                    whileWaitingUntil(timeout));     assertThat(element, should(exist...
public void shouldSeeSuggest(Matcher mchr) {         assertThat(               onSearchPage().getSuggest(), mchr);     }  ...
public void shouldSeeSuggest(Matcher mchr) {         assertThat(               onSearchPage().getSuggest(), mchr);     }  ...
public void shouldSeeSuggest(Matcher mchr) {         assertThat(               onSearchPage().getSuggest(), mchr);     }  ...
public void shouldSeeSuggest(Matcher mchr) {         assertThat(               onSearchPage().getSuggest(), mchr);     }  ...
public void shouldSeeSuggest(Matcher mchr) {         assertThat(               onSearchPage().getSuggest(), mchr);     }  ...
98
<dependency>         <groupId>           ru.yandex.qatools.htmlelements         </groupId>        <artifactId>          ht...
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
Upcoming SlideShare
Loading in …5
×

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

1,955 views

Published on

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

Published in: Technology, Sports
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,955
On SlideShare
0
From Embeds
0
Number of Embeds
1,225
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

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

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

×