HtmlElements - естественное расширение PageObject

2,197 views

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,197
On SlideShare
0
From Embeds
0
Number of Embeds
893
Actions
Shares
0
Downloads
14
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

HtmlElements - естественное расширение PageObject

  1. 1. HtmlElements -естественное расширениеPageObjectКошелев АртёмРуководитель группы тестирования 1
  2. 2. Кошелев АртёмРуководитель группытестированияart.koshelev@yandex-team.rutwitter: @art_koshelev 2
  3. 3. 3
  4. 4. h"ps://github.com/yandex6qatools/htmlelements94
  5. 5. 5
  6. 6. 6
  7. 7. 7
  8. 8. 8
  9. 9. 9
  10. 10. 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(“Заданным условиям не соответствует ни один товар”)); ! }10
  11. 11. 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(“Заданным условиям не соответствует ни один товар”)); ! }11
  12. 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(“Заданным условиям не соответствует ни один товар”)); ! }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. 16
  17. 17. 17
  18. 18. 18
  19. 19. 19
  20. 20. 20
  21. 21. 21
  22. 22. 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); ! } ……22
  23. 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); ! } ……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 { ! …… ! public SearchResultsPage lookFor(String item) { ! ! searchInput.type(item); ! ! searchButton.click(); ! ! return new SearchResultsPage(driver); ! } ! public CatalogModelsPage clickOnElectronicLink() { ! ! electronikLink.click(); ! ! return new CatalogModelsPage(driver); ! } ……!26
  27. 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); ! } ……!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. HomePage onHomePage; SearchResultsPage onResultsPage; @Test public void canSearch() { ! onHomePage = new HomePage(driver).open(); ! onResultsPage = onHomePage.lookFor(“чикипибарум”); assertThat(onResultsPage.errorMessage(), ! ! ! is(“Заданным условиям не соответствует ни один товар.”)); }29
  30. 30. HomePage onHomePage; SearchResultsPage onResultsPage; @Test public void canSearch() { ! onHomePage = new HomePage(driver).open(); ! onResultsPage = onHomePage.lookFor(“чикипибарум”); assertThat(onResultsPage.errorMessage(), ! ! ! is(“Заданным условиям не соответствует ни один товар.”)); }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. 32
  33. 33. 33
  34. 34. 34
  35. 35. 35
  36. 36. 36
  37. 37. public class HomePage extends PageObject { ! @FindBy(css = “input#search-input”) ! private WebElement searchInput; ! @FindBy(css = “td.b-search__button”) ! private WebElement searchButton;37
  38. 38. 38
  39. 39. 39
  40. 40. 40
  41. 41. 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. @Block(@FindBy(…)) public class SearchArrow extends HtmlElement { ! ! @FindBy(…) ! ! private WebElement searchInput; ! ! @FindBy(…) ! ! private WebElement searchButton; }55
  56. 56. @Block(@FindBy(…)) public class SearchArrow extends HtmlElement { ! ! @FindBy(…) ! ! private WebElement searchInput; ! ! @FindBy(…) ! ! private WebElement searchButton; }56
  57. 57. @Block(@FindBy(…)) public class SearchArrow extends HtmlElement { ! ! @FindBy(…) ! ! private WebElement searchInput; ! ! @FindBy(…) ! ! private WebElement searchButton; }57
  58. 58. @Block(@FindBy(…)) public class SearchArrow extends HtmlElement { ! ! @FindBy(…) ! ! private WebElement searchInput; ! ! @FindBy(…) ! ! private WebElement searchButton; }58
  59. 59. 59
  60. 60. @Block(@FindBy(…)) public class SearchBlock extends HtmlElement { ! ! private SearchArrow arrow; ! ! private SearchTabs tabs; }60
  61. 61. public class HomePage extends PageObject { ! ! public SearchArrow arrow; }61
  62. 62. public class HomePage extends PageObject { @FindBy(xpath = “//different_locator”) ! ! public SearchArrow arrow; }62
  63. 63. @Block(@FindBy(…)) public class SearchArrow extends HtmlElement { ! ! @FindBy(…) ! ! private WebElement searchInput; ! ! @FindBy(…) ! ! private WebElement searchButton; }63
  64. 64. 64
  65. 65. @Block(@FindBy(…)) public class SearchArrow extends HtmlElement { ! ! @FindBy(…) ! ! private TextInput searchInput; ! ! @FindBy(…) ! ! private Button searchButton; }65
  66. 66. 66
  67. 67. public class Link extends TypifiedElement { ! public Link(WebElement wrappedElement) { ! ! super(wrappedElement) ! } ...... }67
  68. 68. public class Link extends TypifiedElement { ...... ! public void click() {…} ! public String getReference() {…} ! public String getText(){…} }68
  69. 69. 69
  70. 70. 70
  71. 71. public class Range extends TypifiedElement { ! public Range(WebElement wrappedElement) { ! ! super(wrappedElement) ! } }71
  72. 72. public class Range extends TypifiedElement { ! @FindBy(…) ! WebElement min; ! @FindBy(…) ! WebElement max; ! ! public setRange(int min, int max) {…} ! public setMin(int min) {…} public setMax(int max) {…} }72
  73. 73. 73
  74. 74. 74
  75. 75. 75
  76. 76. 76
  77. 77. 77
  78. 78. public class HomePage extends PageObject { … ! @FindBy(css = “div.suggest”) ! private WebElement suggest; …78
  79. 79. 79
  80. 80. @Block(@FindBy(xpath = “div[@class*=‘search__arr’]”)) @Name(“Поисковая стрела”) public class SearchArrow extends HtmlElement { ! ! @FindBy(xpath = “.//input”) ! ! @Name(“Поисковый запрос”) ! ! private TextInput searchInput; ! ! @FindBy(xpath = “.//input[@type=‘submit’]”) ! ! private Button searchButton; }80
  81. 81. @Block(@FindBy(xpath = “div[@class*=‘search__arr’]”)) @Name(“Поисковая стрела”) public class SearchArrow extends HtmlElement { ! ! @FindBy(xpath = “.//input”) ! ! @Name(“Поисковый запрос”) ! ! private TextInput searchInput; ! ! @FindBy(xpath = “.//input[@type=‘submit’]”) ! ! private Button searchButton; }81
  82. 82. 82
  83. 83. assertThat(actual, Matcher);83
  84. 84. assertThat(str, is(“Everybody dance now!”)); assertThat(year, lessThan(1999)); assertThat(year, both(lessThan(1999)). ! ! ! ! ! and(greaterThan(1990)));84
  85. 85. 85
  86. 86. @FindBy(…) private WebElement firstSuggest; assertThat(firstSuggest, hasText(“canon”));86
  87. 87. @FindBy(…) private WebElement firstSuggest; assertThat(firstSuggest, hasText(“canon”));87
  88. 88. @FindBy(…) private WebElement firstSuggest; assertThat(firstSuggest, hasText(“canon”));88
  89. 89. @FindBy(…) private List<WebElement> suggest; assertThat(suggest, hasItem(hasText(“canon”)));89
  90. 90. @FindBy(…) private List<WebElement> suggest; assertThat(suggest, hasItem(hasText(“canon”)));90
  91. 91. @FindBy(…) private List<WebElement> suggest; assertThat(suggest, hasItem(hasText(“canon”)));91
  92. 92. @FindBy(…) private List<WebElement> suggest; assertThat(suggest, hasItem(hasText(“canon”)));92
  93. 93. 93
  94. 94. <dependency> <groupId> ru.yandex.qatools.htmlelements </groupId> <artifactId> htmlelements-java </artifactId> <version>1.9</version> </dependency>94
  95. 95. 95
  96. 96. 96
  97. 97. 97
  98. 98. 98
  99. 99. @FindBy(…) private List<WebElement> suggest; assertThat(suggest, hasItem(hasText(“canon”)));99
  100. 100. @FindBy(…) private List<WebElement> suggest; assertThat(suggest, withWaitFor(hasItem(hasText(“canon”))));100
  101. 101. 101
  102. 102. 102
  103. 103. 103
  104. 104. 104
  105. 105. 105
  106. 106. 106
  107. 107. 107
  108. 108. h"p://bit.ly/yqahegg0 h"ps://github.com/yandex6qatools/htmlelements9108
  109. 109. Кошелев АртёмРуководитель группытестированияart.koshelev@yandex-team.rutwitter: @art_koshelev 109

×