ElementService extends BaseServiceHub { public WebElement translateLocatorToWebElement(String locatorString) { return findExpectedElement(translateLocator(locatorString)); }  WebElement translateLocatorToWebElement(String locatorString); By translateLocator(String locatorString); WebElement findExpectedElement(By by); WebElement findExpectedElement(By by, boolean includeHiddenElements); List<WebElement> findExpectedElements(By by); WebElement findExpectedFirstMatchedElement(By... bys); WebElement findExpectedFirstMatchedElement(int timeoutInSeconds, By... bys); String constructCaseInsensitiveContains(String identifier, String value); void isElementVisible(By locator, boolean visible); void isElementVisible(WebElement element, boolean visible); boolean getElementExists(By locator); void waitForLoaders(); void assertExpectedGlobalConditions(); void dragElementTo(String draggable, String droppable); void dragElementTo(String draggable, String droppable, int waitForMillies); void dragElementTo(By draggable, By droppable); void dragElementTo(By draggable, int x, int y); void ieSaveButtonClick(WebElement button); void waitForInvisibilityOfElement(WebElement element); WebElement getElementFromReferencedView(String viewName, String elementName); String getElementLocatorFromReferencedView(String viewName, String elementName); FindBy getFindByDescriptor(String viewName, String elementName); WebElement viewShouldContainElement(String viewName, String elementName); void viewShouldNotShowElement(String viewName, String elementName); WebElement viewShouldShowElement(String viewName, String elementName); static final String XPATH_LOCATOR_PREFIX; static final String ID_LOCATOR_PREFIX; static final String NAME_ATTRIBUTE_LOCATOR_PREFIX; static final String CSS_LOCATOR_PREFIX; }
@Test public void testFindExpectedElement_delayedDisplay() throws IOException { seleniumNavigationService.navigate_to_url(MockReferenceDatePopulator.DELAYED_DISPLAY_TEST_PAGE_URL); seleniumElementService.translateLocatorToWebElement(ElementService.ID_LOCATOR_PREFIX + "delayedDisplayButton").click(); WebElement foundText = seleniumElementService.translateLocatorToWebElement(ElementService.ID_LOCATOR_PREFIX + "text"); assertNotNull(foundText); assertEquals("I should show after a delay", foundText.getText()); }
@Test public void testInterpretLocator_referenceName() throws IOException { seleniumNavigationService.navigate_to_url(MockReferenceDatePopulator.TABLE_TEST_PAGE_URL); WebElement foundLocator = seleniumElementService.translateLocatorToWebElement("Table locator"); assertNotNull(foundLocator); }
@Test public void testInterpretLocator_nameAttribute() throws IOException { seleniumNavigationService.navigate_to_url(MockReferenceDatePopulator.TABLE_TEST_PAGE_URL); WebElement foundLocator = seleniumElementService.translateLocatorToWebElement(ElementService.NAME_ATTRIBUTE_LOCATOR_PREFIX + "cell_2_1"); assertNotNull(foundLocator); assertEquals("Table cell 3", foundLocator.getText()); }
@Test(expected = AssertionError.class) public void testInterpretLocator_nonExistingName() throws IOException { seleniumNavigationService.navigate_to_url(MockReferenceDatePopulator.TABLE_TEST_PAGE_URL); seleniumElementService.translateLocatorToWebElement(ElementService.NAME_ATTRIBUTE_LOCATOR_PREFIX + "I_dont_exist"); }
@Test public void testInterpitLocator_xpath() throws IOException { seleniumNavigationService.navigate_to_url(MockReferenceDatePopulator.TABLE_TEST_PAGE_URL); WebElement foundLocator = seleniumElementService.translateLocatorToWebElement(ElementService.XPATH_LOCATOR_PREFIX + " assertNotNull(foundLocator); }
@Test public void testInterpitLocator_css() throws IOException { seleniumNavigationService.navigate_to_url(MockReferenceDatePopulator.TABLE_TEST_PAGE_URL); WebElement foundElement = seleniumElementService.translateLocatorToWebElement(ElementService.CSS_LOCATOR_PREFIX + "#row1.odd"); assertNotNull(foundElement); assertEquals("tr", foundElement.getTagName()); }
@Test(expected = AssertionError.class) public void testInterpitLocator_nonExistingXpath() throws IOException { seleniumNavigationService.navigate_to_url(MockReferenceDatePopulator.TABLE_TEST_PAGE_URL); seleniumElementService.translateLocatorToWebElement(ElementService.XPATH_LOCATOR_PREFIX + " }
@Test public void testInterpitLocator_id() throws IOException { seleniumNavigationService.navigate_to_url(MockReferenceDatePopulator.TABLE_TEST_PAGE_URL); WebElement foundLocator = seleniumElementService.translateLocatorToWebElement(ElementService.ID_LOCATOR_PREFIX + "exampleTable"); assertNotNull(foundLocator); }
@Test(expected = AssertionError.class) public void testInterpitLocator_wrongId() throws IOException { seleniumNavigationService.navigate_to_url(MockReferenceDatePopulator.TABLE_TEST_PAGE_URL); seleniumElementService.translateLocatorToWebElement(ElementService.ID_LOCATOR_PREFIX + "non_existing_id"); }