View Javadoc

1   package com.atlassian.pageobjects.elements.test;
2   
3   import com.atlassian.pageobjects.browser.Browser;
4   import com.atlassian.pageobjects.browser.IgnoreBrowser;
5   import com.atlassian.pageobjects.elements.PageElement;
6   import com.atlassian.pageobjects.elements.TimedElement;
7   import com.atlassian.pageobjects.elements.query.Poller;
8   import com.atlassian.pageobjects.elements.test.pageobjects.page.ElementsPage;
9   import com.atlassian.pageobjects.elements.timeout.TimeoutType;
10  import org.junit.Test;
11  import org.openqa.selenium.By;
12  
13  import static junit.framework.Assert.assertEquals;
14  import static org.hamcrest.Matchers.equalToIgnoringCase;
15  
16  @IgnoreBrowser(Browser.HTMLUNIT_NOJS)
17  public class TestTimedElement extends AbstractPageElementBrowserTest
18  {
19      @Test
20      public void testIsPresent()
21      {
22          product.visit(ElementsPage.class);
23  
24          // Positive - verify element that exists
25          Poller.waitUntilTrue(product.find(By.id("test1_addElementsButton")).timed().isPresent());
26  
27          // Negative - verify element that does not exist
28          Poller.waitUntilFalse(product.find(By.id("non_present_element")).timed().isPresent());
29  
30          // Delayed presence & Delayed positive - click on button that adds a span with delay, verify isPresent waits.
31          product.find(By.id("test1_addElementsButton")).click();
32          Poller.waitUntilTrue(product.find(By.id("test1_delayedSpan")).timed().isPresent());
33  
34          // Delayed Negative
35      }
36  
37      @Test
38      public void testIsVisible()
39      {
40          product.visit(ElementsPage.class);
41  
42          TimedElement testInput = product.find(By.id("test2_input")).timed();
43  
44          // Positive - verify input that is visible
45          Poller.waitUntilTrue(testInput.isVisible());
46  
47          // Negative - click on button to make input invisible and verify
48          product.find(By.id("test2_toggleInputVisibility")).click();
49          Poller.waitUntilFalse(testInput.isVisible());
50  
51          // Delayed presence - click on a button that adds an element with delay, verify isVisible waits
52          product.find(By.id("test2_addElementsButton")).click();
53          Poller.waitUntilTrue(product.find(By.id("test2_delayedSpan")).timed().isVisible());
54  
55          // Delayed positive - click on button to make input visible with delay and verify
56          product.find(By.id("test2_toggleInputVisibilityWithDelay")).click();
57          Poller.waitUntilTrue(testInput.isVisible());
58  
59          // Delayed Negative
60      }
61  
62      @Test
63      public void testText()
64      {
65          product.visit(ElementsPage.class);
66  
67          // Positive - verify span with text
68          Poller.waitUntilEquals("Span Value", product.find(By.id("test3_span")).timed().getText());
69  
70          // check non-case-sensitive
71          Poller.waitUntil(product.find(By.id("test3_span")).timed().getText(), equalToIgnoringCase("span value"));
72  
73          // Negative - verify a span that has no text
74          Poller.waitUntilEquals("", product.find(By.id("test3_spanEmpty")).timed().getText());
75  
76          // Delayed presence - click on button that adds a span with delay, verify getText waits
77          product.find(By.id("test3_addElementsButton")).click();
78          Poller.waitUntilEquals("Delayed Span", product.find(By.id("test3_delayedSpan")).timed().getText());
79  
80          // Delayed postive - click on button that sets the text of span with delay, verify getText waits
81          product.find(By.id("test3_setTextButton")).click();
82          Poller.waitUntilEquals("Delayed Text", product.find(By.id("test3_spanEmpty")).timed().getText());
83  
84          // Delayed negative
85      }
86  
87      @Test
88      public void testHasText()
89      {
90          product.visit(ElementsPage.class);
91  
92          // Positive - verify span with text
93          Poller.waitUntilTrue(product.find(By.id("test3_span")).timed().hasText("Span Value"));
94  
95          // Negative - verify span with wrong text
96          Poller.waitUntilFalse(product.find(By.id("test3_spanEmpty")).timed().hasText("foo"));
97  
98          // Delayed presence - click on button that adds a span with delay, verify getText waits
99          product.find(By.id("test3_addElementsButton")).click();
100         Poller.waitUntilTrue(product.find(By.id("test3_delayedSpan")).timed().hasText("Delayed Span"));
101     }
102 
103     @Test
104     public void testAttribute()
105     {
106         product.visit(ElementsPage.class);
107 
108         // Positive - verify class attribute of span
109         Poller.waitUntilEquals("test5-input-class", product.find(By.id("test5_input")).timed().getAttribute("class"));
110 
111         // Negative
112 
113         // Delayed presence - click on button that adds a span with delay, verify getAtribute waits
114         product.find(By.id("test5_addElementsButton")).click();
115         Poller.waitUntilEquals("test5-span-delayed", product.find(By.id("test5_delayedSpan")).timed().getAttribute("class"));
116 
117         // Delayed positive - click on a button that adds attribute of a span, verify getAttribute waits
118         product.find(By.id("test5_addAttribute")).click();
119         Poller.waitUntilEquals("test5-input-value", product.find(By.id("test5_input")).timed().getAttribute("value"));
120 
121         // Delayed negative
122     }
123 
124     @Test
125     public void testTimedElementLocatesElementWithinAContext()
126     {
127         product.visit(ElementsPage.class);
128 
129         product.find(By.id("test6_hideSpanButton")).click();
130         Poller.waitUntilFalse(product.find(By.id("test6_Div")).find(By.className("test6_class")).timed().isVisible());
131     }
132 
133     @Test
134     public void testGetTagName()
135     {
136         product.visit(ElementsPage.class);
137 
138         product.find(By.id("test1_addElementsButton")).click();
139         Poller.waitUntilEquals("span", product.find(By.id("test1_delayedSpan")).timed().getTagName());
140     }
141 
142     @Test
143     public void testHasAttribute()
144     {
145         product.visit(ElementsPage.class);
146 
147         // Delayed presence
148         product.find(By.id("test1_addElementsButton")).click();
149         Poller.waitUntilTrue(product.find(By.id("test1_delayedSpan")).timed().hasAttribute("class", "testClass"));
150 
151         // incorrect attribute
152         Poller.waitUntilFalse(product.find(By.id("test1_delayedSpan")).timed().hasAttribute("class", "foo"));
153 
154         // attribute not present
155         Poller.waitUntilFalse(product.find(By.id("test1_delayedSpan")).timed().hasAttribute("nonexistant", "foo"));
156     }
157 
158     @Test
159     public void testTimedElementWithFindAll()
160     {
161         product.visit(ElementsPage.class);
162         PageElement leafList = product.find(By.id("test4_leafList"));
163         for (PageElement li : leafList.findAll(By.tagName("li")))
164         {
165             Poller.waitUntilTrue(li.timed().isPresent());
166         }
167     }
168 
169     @Test
170     public void testElementWithTimeout()
171     {
172         product.visit(ElementsPage.class);
173         PageElement element = product.find(By.id("test1_addElementsButton"));
174         assertEquals(element.timed().isPresent().defaultTimeout(), product.timeouts().timeoutFor(TimeoutType.DEFAULT));
175         element = element.withTimeout(TimeoutType.AJAX_ACTION);
176         assertEquals(element.timed().isPresent().defaultTimeout(), product.timeouts().timeoutFor(TimeoutType.AJAX_ACTION));
177     }
178 
179     @Test
180     public void testGetValue()
181     {
182         product.visit(ElementsPage.class);
183 
184         final PageElement testedInput = product.find(By.id("test9_input"));
185         final PageElement toggleValueButton = product.find(By.id("test9_toggleValue"));
186 
187         Poller.waitUntilEquals("test9_value", testedInput.timed().getValue());
188 
189         toggleValueButton.click();
190         Poller.waitUntilEquals("test9_newvalue", testedInput.timed().getValue());
191 
192         // ... and switch again!
193         toggleValueButton.click();
194         Poller.waitUntilEquals("test9_value", testedInput.timed().getValue());
195     }
196 
197     @Test
198     public void testHasValue()
199     {
200         product.visit(ElementsPage.class);
201 
202         final PageElement testedInput = product.find(By.id("test9_input"));
203         final PageElement toggleValueButton = product.find(By.id("test9_toggleValue"));
204 
205         Poller.waitUntilTrue(testedInput.timed().hasValue("test9_value"));
206 
207         toggleValueButton.click();
208         Poller.waitUntilTrue(testedInput.timed().hasValue("test9_newvalue"));
209 
210         // ... and switch again!
211         toggleValueButton.click();
212         Poller.waitUntilTrue(testedInput.timed().hasValue("test9_value"));
213     }
214 }