Advertisement
VDzhevalov

Smoke e2e v1

Aug 1st, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.69 KB | None | 0 0
  1. package lessons.tests.vladimir.todomvc.smoke.v3;
  2.  
  3. import com.codeborne.selenide.ElementsCollection;
  4. import com.codeborne.selenide.SelenideElement;
  5. import org.junit.After;
  6. import org.junit.Before;
  7. import org.junit.Test;
  8. import org.openqa.selenium.By;
  9.  
  10. import static com.codeborne.selenide.CollectionCondition.empty;
  11. import static com.codeborne.selenide.CollectionCondition.exactTexts;
  12. import static com.codeborne.selenide.Condition.*;
  13. import static com.codeborne.selenide.Selenide.*;
  14.  
  15. /**
  16. * Created by Vladimir on 20.07.2016.
  17. */
  18. public class TodoMVCTest {
  19.  
  20. @Before
  21. public void testSetup() {
  22. open("https://todomvc4tasj.herokuapp.com/");
  23. }
  24.  
  25. @After
  26. public void clearData() {
  27. executeJavaScript("localStorage.clear()");
  28. }
  29.  
  30. @Test
  31. public void testTasksLifeCycle() {
  32.  
  33. addTasks("a");
  34. assertTasksAre("a");
  35. assertItemsLeft(1);
  36. toggleAllTasks();
  37. assertItemsLeft(0);
  38.  
  39. filterActive();
  40. assertVisibleTasksListIsEmpty();
  41. addTasks("b");
  42. toggleTask("b");
  43. assertItemsLeft(0);
  44. assertVisibleTasksListIsEmpty();
  45.  
  46. filterCompleted();
  47. assertVisibleTasksAre("a","b");
  48. //Activate
  49. toggleTask("a");
  50. assertVisibleTasksAre("b");
  51. assertItemsLeft(1);
  52. clearCompleted();
  53. assertVisibleTasksListIsEmpty();
  54. }
  55.  
  56. @Test
  57. public void testTaskDelete() {
  58. addTasks("a","b");
  59. filterActive();
  60. assertItemsLeft(2);
  61. deleteTask("a");
  62. assertItemsLeft(1);
  63. deleteTask("b");
  64. assertTasksListIsEmpty();
  65. }
  66.  
  67. @Test
  68. public void testTaskCancelChanges(){
  69. addTasks("a");
  70. filterActive();
  71. startEditTask("a", "a edit canceled").pressEscape();
  72. assertTasksAre("a");
  73. assertItemsLeft(1);
  74. }
  75.  
  76. @Test
  77. public void testTaskUpdate(){
  78. addTasks("a");
  79. startEditTask("a", "a edit").pressEnter();
  80. assertTasksAre("a edit");
  81. assertItemsLeft(1);
  82. }
  83.  
  84. ElementsCollection tasks = $$("#todo-list>li");
  85.  
  86. private void addTasks(String... texts) {
  87. for (String text : texts) {
  88. $("#new-todo").setValue(text).pressEnter();
  89. }
  90. }
  91.  
  92. private void assertTasksAre(String... texts) {
  93. tasks.shouldHave(exactTexts(texts));
  94. }
  95.  
  96. private void assertVisibleTasksAre(String... texts) {
  97. tasks.filterBy(visible).shouldHave(exactTexts(texts));
  98. }
  99.  
  100. private void assertVisibleTasksListIsEmpty() {
  101. tasks.filterBy(visible).shouldBe(empty);
  102. }
  103.  
  104. private void assertTasksListIsEmpty() {
  105. tasks.shouldBe(empty);
  106. }
  107.  
  108. private void assertItemsLeft(Integer counter) {
  109. $("#todo-count").$("strong").shouldHave(exactText(counter+""));
  110. }
  111.  
  112. private void clearCompleted() {
  113. $("#clear-completed").click();
  114. }
  115.  
  116. private void deleteTask(String text) {
  117. tasks.find(exactText(text)).hover().$(".destroy").click();
  118. }
  119.  
  120. private void toggleTask(String text) {
  121. tasks.find(exactText(text)).$(".toggle").click();
  122. }
  123.  
  124. private void toggleAllTasks() {
  125. $("#toggle-all").click();
  126. }
  127.  
  128. private void filterAll() {
  129. $(By.linkText("All")).click();
  130. }
  131.  
  132. private void filterActive() {
  133. $(By.linkText("Active")).click();
  134. }
  135.  
  136. private void filterCompleted() {
  137. $(By.linkText("Completed")).click();
  138. }
  139.  
  140. private SelenideElement startEditTask(String oldText, String newText) {
  141. tasks.find(exactText(oldText)).doubleClick();
  142. return tasks.find(cssClass("editing")).find(".edit").setValue(newText);
  143. }
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement