List of usage examples for org.openqa.selenium WebElement getTagName
String getTagName();
From source file:com.consol.citrus.cucumber.step.runner.selenium.SeleniumStepsTest.java
License:Apache License
@Test public void testClick() { SeleniumBrowserConfiguration endpointConfiguration = new SeleniumBrowserConfiguration(); when(seleniumBrowser.getName()).thenReturn("seleniumBrowser"); when(seleniumBrowser.getWebDriver()).thenReturn(webDriver); when(seleniumBrowser.getEndpointConfiguration()).thenReturn(endpointConfiguration); WebElement element = Mockito.mock(WebElement.class); when(element.isDisplayed()).thenReturn(true); when(element.isEnabled()).thenReturn(true); when(element.getTagName()).thenReturn("button"); when(webDriver.findElement(any(By.class))).thenAnswer(invocation -> { By select = (By) invocation.getArguments()[0]; Assert.assertEquals(select.getClass(), By.ById.class); Assert.assertEquals(select.toString(), "By.id: foo"); return element; });// w w w .j a va2s .c om steps.setBrowser("seleniumBrowser"); steps.click("id", "foo"); Assert.assertEquals(runner.getTestCase().getActionCount(), 1L); Assert.assertTrue(((DelegatingTestAction) runner.getTestCase().getTestAction(0)) .getDelegate() instanceof SeleniumAction); SeleniumAction action = (SeleniumAction) ((DelegatingTestAction) runner.getTestCase().getTestAction(0)) .getDelegate(); Assert.assertEquals(action.getBrowser(), seleniumBrowser); Assert.assertTrue(action instanceof ClickAction); Assert.assertEquals(((ClickAction) action).getProperty(), "id"); Assert.assertEquals(((ClickAction) action).getPropertyValue(), "foo"); verify(element).click(); }
From source file:com.consol.citrus.cucumber.step.runner.selenium.SeleniumStepsTest.java
License:Apache License
@Test public void testSetInput() { SeleniumBrowserConfiguration endpointConfiguration = new SeleniumBrowserConfiguration(); when(seleniumBrowser.getName()).thenReturn("seleniumBrowser"); when(seleniumBrowser.getWebDriver()).thenReturn(webDriver); when(seleniumBrowser.getEndpointConfiguration()).thenReturn(endpointConfiguration); WebElement element = Mockito.mock(WebElement.class); when(element.isDisplayed()).thenReturn(true); when(element.isEnabled()).thenReturn(true); when(element.getTagName()).thenReturn("input"); when(webDriver.findElement(any(By.class))).thenReturn(element); steps.setBrowser("seleniumBrowser"); steps.setInput("Hello", "id", "foo"); Assert.assertEquals(runner.getTestCase().getActionCount(), 1L); Assert.assertTrue(((DelegatingTestAction) runner.getTestCase().getTestAction(0)) .getDelegate() instanceof SeleniumAction); SeleniumAction action = (SeleniumAction) ((DelegatingTestAction) runner.getTestCase().getTestAction(0)) .getDelegate();/*from ww w . j a va 2s .c om*/ Assert.assertEquals(action.getBrowser(), seleniumBrowser); Assert.assertTrue(action instanceof SetInputAction); Assert.assertEquals(((SetInputAction) action).getValue(), "Hello"); Assert.assertEquals(((SetInputAction) action).getProperty(), "id"); Assert.assertEquals(((SetInputAction) action).getPropertyValue(), "foo"); verify(element).clear(); verify(element).sendKeys("Hello"); }
From source file:com.consol.citrus.cucumber.step.runner.selenium.SeleniumStepsTest.java
License:Apache License
@Test public void testCheckInput() { SeleniumBrowserConfiguration endpointConfiguration = new SeleniumBrowserConfiguration(); when(seleniumBrowser.getName()).thenReturn("seleniumBrowser"); when(seleniumBrowser.getWebDriver()).thenReturn(webDriver); when(seleniumBrowser.getEndpointConfiguration()).thenReturn(endpointConfiguration); WebElement element = Mockito.mock(WebElement.class); when(element.isDisplayed()).thenReturn(true); when(element.isEnabled()).thenReturn(true); when(element.getTagName()).thenReturn("input"); when(webDriver.findElement(any(By.class))).thenReturn(element); steps.setBrowser("seleniumBrowser"); steps.checkInput("check", "id", "foo"); Assert.assertEquals(runner.getTestCase().getActionCount(), 1L); Assert.assertTrue(((DelegatingTestAction) runner.getTestCase().getTestAction(0)) .getDelegate() instanceof SeleniumAction); SeleniumAction action = (SeleniumAction) ((DelegatingTestAction) runner.getTestCase().getTestAction(0)) .getDelegate();/*from w ww.j a v a 2 s . c om*/ Assert.assertEquals(action.getBrowser(), seleniumBrowser); Assert.assertTrue(action instanceof CheckInputAction); Assert.assertEquals(((CheckInputAction) action).isChecked(), true); Assert.assertEquals(((CheckInputAction) action).getProperty(), "id"); Assert.assertEquals(((CheckInputAction) action).getPropertyValue(), "foo"); verify(element).click(); }
From source file:com.consol.citrus.cucumber.step.runner.selenium.SeleniumStepsTest.java
License:Apache License
@Test public void testShouldDisplay() { SeleniumBrowserConfiguration endpointConfiguration = new SeleniumBrowserConfiguration(); when(seleniumBrowser.getName()).thenReturn("seleniumBrowser"); when(seleniumBrowser.getWebDriver()).thenReturn(webDriver); when(seleniumBrowser.getEndpointConfiguration()).thenReturn(endpointConfiguration); WebElement element = Mockito.mock(WebElement.class); when(element.isDisplayed()).thenReturn(true); when(element.isEnabled()).thenReturn(true); when(element.getTagName()).thenReturn("button"); when(webDriver.findElement(any(By.class))).thenAnswer(invocation -> { By select = (By) invocation.getArguments()[0]; Assert.assertEquals(select.getClass(), By.ByName.class); Assert.assertEquals(select.toString(), "By.name: foo"); return element; });//from www . j a v a 2 s .com steps.setBrowser("seleniumBrowser"); steps.should_display("name", "foo"); Assert.assertEquals(runner.getTestCase().getActionCount(), 1L); Assert.assertTrue(((DelegatingTestAction) runner.getTestCase().getTestAction(0)) .getDelegate() instanceof SeleniumAction); SeleniumAction action = (SeleniumAction) ((DelegatingTestAction) runner.getTestCase().getTestAction(0)) .getDelegate(); Assert.assertEquals(action.getBrowser(), seleniumBrowser); Assert.assertTrue(action instanceof FindElementAction); Assert.assertEquals(((FindElementAction) action).getProperty(), "name"); Assert.assertEquals(((FindElementAction) action).getPropertyValue(), "foo"); }
From source file:com.consol.citrus.selenium.actions.FindElementAction.java
License:Apache License
/** * Validates found web element with expected content. * @param element/* w w w . j a va2s . c o m*/ * @param browser * @param context */ protected void validate(WebElement element, SeleniumBrowser browser, TestContext context) { validateElementProperty("tag-name", tagName, element.getTagName(), context); validateElementProperty("text", text, element.getText(), context); Assert.isTrue(displayed == element.isDisplayed(), String.format( "Selenium web element validation failed, " + "property 'displayed' expected '%s', but was '%s'", displayed, element.isDisplayed())); Assert.isTrue(enabled == element.isEnabled(), String.format( "Selenium web element validation failed, " + "property 'enabled' expected '%s', but was '%s'", enabled, element.isEnabled())); for (Map.Entry<String, String> attributeEntry : attributes.entrySet()) { validateElementProperty(String.format("attribute '%s'", attributeEntry.getKey()), attributeEntry.getValue(), element.getAttribute(attributeEntry.getKey()), context); } for (Map.Entry<String, String> styleEntry : styles.entrySet()) { validateElementProperty(String.format("css style '%s'", styleEntry.getKey()), styleEntry.getValue(), element.getCssValue(styleEntry.getKey()), context); } }
From source file:com.consol.citrus.selenium.actions.FindElementAction.java
License:Apache License
/** * Subclasses may override this method in order to add element actions. * @param element/*from w w w . jav a2s.c om*/ * @param browser * @param context */ protected void execute(WebElement element, SeleniumBrowser browser, TestContext context) { if (StringUtils.hasText(element.getTagName())) { context.setVariable(element.getTagName(), element); } }
From source file:com.consol.citrus.selenium.actions.SetInputAction.java
License:Apache License
@Override protected void execute(WebElement webElement, SeleniumBrowser browser, TestContext context) { super.execute(webElement, browser, context); String tagName = webElement.getTagName(); if (null == tagName || !"select".equals(tagName.toLowerCase())) { webElement.clear();//from w w w . j a v a2 s. c o m webElement.sendKeys(value); } else { new Select(webElement).selectByValue(value); } }
From source file:com.consol.citrus.selenium.client.WebClient.java
License:Apache License
/** * Set a value on a single input element by its id after clearing it. * * @param by//from w w w. j a v a 2 s. com * @param value Value to set. */ public void setInput(By by, String value) { WebElement element = findElement(by); String tagName = element.getTagName(); if (null == tagName || !"select".equals(tagName.toLowerCase())) { element.clear(); element.sendKeys(value); } else { new Select(element).selectByValue(value); } }
From source file:com.demo.selenium.example.GridExampleTest.java
License:Apache License
@Test public void GridTwoNodeTest() throws MalformedURLException, InterruptedException { DesiredCapabilities aDesiredcap = DesiredCapabilities.chrome(); WebDriver dr = new RemoteWebDriver(new URL("http://172.19.6.46:5555/wd/hub"), aDesiredcap); dr.get("http://www.baidu.com"); dr.manage().window().maximize();//w ww.j a v a 2 s.c om String str[] = new String[] { "java", "selenium", "spring", "mybatis", "jps", "grid", "mysql", "iphone" }; for (String string : str) { WebElement element = dr.findElement(By.xpath(".//*[@id='kw']")); element.clear(); element.sendKeys(string); Thread.sleep(1000); WebElement buttons = dr.findElement(By.xpath(".//*[@id='su']")); System.out.println(buttons.getTagName()); buttons.click(); } Thread.sleep(2000); dr.close(); }
From source file:com.dhenton9000.filedownloader.FileDownloader.java
License:Apache License
/** * Perform an HTTP Status Check upon/Download the file specified in the href attribute of a WebElement * * @param anchorElement Selenium WebElement * @throws Exception// ww w.ja v a2 s. c o m */ public void setURISpecifiedInAnchorElement(WebElement anchorElement) throws Exception { if (anchorElement.getTagName().equals("a")) { fileURI = new URI(anchorElement.getAttribute("href")); } else { throw new Exception("You have not specified an <a> element!"); } }