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.GlobalElementFinder;
6   import com.atlassian.pageobjects.elements.PageElement;
7   import com.atlassian.pageobjects.elements.PageElementActions;
8   import com.atlassian.pageobjects.elements.PageElementFinder;
9   import com.atlassian.pageobjects.elements.test.pageobjects.page.ElementsPage;
10  import org.junit.Before;
11  import org.junit.Test;
12  import org.openqa.selenium.By;
13  import org.openqa.selenium.Keys;
14  
15  import javax.inject.Inject;
16  
17  import static junit.framework.Assert.assertNotNull;
18  
19  @IgnoreBrowser({ Browser.HTMLUNIT_NOJS, Browser.HTMLUNIT })
20  public class TestPageElementActions extends AbstractPageElementBrowserTest
21  {
22      private PageElementFinder elementFinder;
23  
24      @Before
25      public void initFinder()
26      {
27          product.visit(ElementsPage.class);
28          elementFinder = product.getPageBinder().bind(GlobalElementFinder.class);
29      }
30  
31      @Test
32      public void shouldGetActionsViaContext()
33      {
34          final PageElementActions actions = product.getPageBinder().bind(PageObjectWithActions.class).actions;
35          assertNotNull(actions);
36          testActions(actions);
37      }
38  
39      @Test
40      public void shouldGetActionsViaPageBinder()
41      {
42          final PageElementActions actions = product.getPageBinder().bind(PageElementActions.class);
43          assertNotNull(actions);
44          testActions(actions);
45      }
46  
47      private void testActions(PageElementActions actions)
48      {
49          final PageElement firstButton = elementFinder.find(By.id("test1_addElementsButton"));
50          final PageElement secondButton = elementFinder.find(By.id("test2_toggleInputVisibility"));
51          final PageElement input = elementFinder.find(By.id("test5_input"));
52          // just make sure it won't blow for now
53          actions.moveToElement(firstButton).click()
54                  .click(secondButton)
55                  .clickAndHold()
56                  .release()
57                  .clickAndHold(firstButton)
58                  .release(firstButton)
59                  .click(input)
60                  .doubleClick()
61                  .doubleClick(firstButton)
62                  .contextClick(secondButton)
63                  .sendKeys(Keys.ESCAPE) // Closes the context menu
64                  .dragAndDrop(firstButton, secondButton)
65                  .dragAndDropBy(secondButton, 10, 10)
66                  .keyDown(Keys.ALT)
67                  .keyUp(Keys.ALT)
68                  .keyDown(firstButton, Keys.CONTROL)
69                  .keyUp(firstButton, Keys.CONTROL)
70                  .moveByOffset(100, 100)
71                  .moveToElement(firstButton)
72                  .moveToElement(secondButton, 10, 10)
73                  .click(input)
74                  .sendKeys("blah")
75                  .click(firstButton)
76                  .sendKeys(input, "moreblah")
77                  .perform();
78      }
79  
80      public static class PageObjectWithActions
81      {
82          @Inject
83          private PageElementActions actions;
84      }
85  
86  }