List of usage examples for org.openqa.selenium By className
public static By className(String className)
From source file:com.consensus.qa.verizon.tests.ExchangeTests.java
private void setUpBackendSimulatorForUpgradeFlow(String phoneNumber) throws InterruptedException, AWTException, IOException { AdminBaseClass adminBaseClass = new AdminBaseClass(); adminBaseClass.launchAdminInNewTab(); PageBase.AdminPage().navigateToSimulator(); PageBase.AdminPage().selectWebAPIResponse(carrierType, BrowserSettings.readConfig("backendSimulator")); PageBase.AdminPage().selectAPIConfig(carrierType); PageBase.AdminPage().selectCreaditReadUseCase("APPROVED_EDGEUP"); PageBase.AdminPage().retrieveCustomerDetails("ELIGIBLE"); PageBase.AdminPage().accountPlanType("Family Share"); PageBase.AdminPage().retrieveExistingCustomerInstallmentsDetails("SUCCESS_NO_PAYMENT"); PageBase.AdminPage().retrievePricePlan("SUCCESS"); PageBase.AdminPage().submitActivation("SUCCESS"); PageBase.AdminPage().submitCreditApplication("APPROVED"); PageBase.AdminPage().submitReciept("SUCCESS"); PageBase.AdminPage().submitServiceDetails("SUCCESS"); PageBase.AdminPage().submitEdgeUpPayment("SUCCESS"); PageBase.AdminPage().returnOrExchangeDevice("SUCCESS"); List<WebElement> phoneList = PageBase.AdminPage().phoneList.findElements(By.className("phoneNumberRow")); if (phoneList.size() > 0) { if (phoneList.size() > 1) { List<WebElement> removePhone = PageBase.AdminPage().phoneList .findElements(By.id("retrieveCustomerDetails_removePhoneNumberRowButton")); for (int i = 0; i < removePhone.size() - 1; i++) { removePhone.get(i).click(); }// w w w .j ava 2s . c o m PageBase.AdminPage().firstPhoneTextBox.clear(); PageBase.AdminPage().firstPhoneTextBox.sendKeys(phoneNumber); } else { PageBase.AdminPage().firstPhoneTextBox.clear(); PageBase.AdminPage().firstPhoneTextBox.sendKeys(phoneNumber); } } else { PageBase.AdminPage().addPhoneNumbers.click(); PageBase.AdminPage().firstPhoneTextBox.clear(); PageBase.AdminPage().firstPhoneTextBox.sendKeys(phoneNumber); } Utilities.implicitWaitSleep(2000); PageBase.AdminPage().save(); }
From source file:com.consensus.qa.verizon.tests.ExchangeTests.java
private void setBackendSimulator(String phoneNumber) throws InterruptedException, AWTException, IOException { AdminBaseClass adminBaseClass = new AdminBaseClass(); adminBaseClass.launchAdminInNewTab(); PageBase.AdminPage().navigateToSimulator(); PageBase.AdminPage().selectWebAPIResponse(carrierType, BrowserSettings.readConfig("backendSimulator")); PageBase.AdminPage().selectAPIConfig(carrierType); PageBase.AdminPage().selectCreaditReadUseCase("APPROVED_EDGEUP"); PageBase.AdminPage().retrieveCustomerDetails("VZW_EDGE_UP_ELIGIBLE"); List<WebElement> phoneList = PageBase.AdminPage().phoneList.findElements(By.className("phoneNumberRow")); if (phoneList.size() > 0) { if (phoneList.size() > 1) { List<WebElement> removePhone = PageBase.AdminPage().phoneList .findElements(By.id("retrieveCustomerDetails_removePhoneNumberRowButton")); for (int i = 0; i < removePhone.size() - 1; i++) { removePhone.get(i).click(); }// w w w . ja v a2s .c o m PageBase.AdminPage().firstPhoneTextBox.clear(); PageBase.AdminPage().firstPhoneTextBox.sendKeys(phoneNumber); } else { PageBase.AdminPage().firstPhoneTextBox.clear(); PageBase.AdminPage().firstPhoneTextBox.sendKeys(phoneNumber); } } else { PageBase.AdminPage().addPhoneNumbers.click(); PageBase.AdminPage().firstPhoneTextBox.clear(); PageBase.AdminPage().firstPhoneTextBox.sendKeys(phoneNumber); } PageBase.AdminPage().accountPlanType("Individual"); PageBase.AdminPage().retrieveExistingCustomerInstallmentsDetails("SUCCESS_WITH_PAYMENT"); PageBase.AdminPage().retrievePricePlan("SUCCESS"); PageBase.AdminPage().submitActivation("SUCCESS"); PageBase.AdminPage().submitCreditApplication("APPROVED"); PageBase.AdminPage().submitReciept("SUCCESS"); PageBase.AdminPage().submitServiceDetails("SUCCESS"); PageBase.AdminPage().submitEdgeUpPayment("SUCCESS"); PageBase.AdminPage().returnOrExchangeDevice("SUCCESS"); Utilities.implicitWaitSleep(2000); PageBase.AdminPage().save(); }
From source file:com.consol.citrus.dsl.runner.SeleniumTestRunnerTest.java
License:Apache License
@Test public void testSeleniumBuilder() { when(applicationContextMock.getBean(TestContext.class)) .thenReturn(applicationContext.getBean(TestContext.class)); when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners()); when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)) .thenReturn(new HashMap<String, SequenceBeforeTest>()); when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)) .thenReturn(new HashMap<String, SequenceAfterTest>()); when(seleniumBrowser.getEndpointConfiguration()).thenReturn(seleniumBrowserConfiguration); when(seleniumBrowserConfiguration.getBrowserType()).thenReturn(BrowserType.CHROME); when(seleniumBrowser.getWebDriver()).thenReturn(webDriver); when(seleniumBrowser.getName()).thenReturn("mockBrowser"); when(applicationContextMock.getBean("mockBrowser", SeleniumBrowser.class)).thenReturn(seleniumBrowser); when(webDriver.navigate()).thenReturn(navigation); when(webDriver.manage()).thenReturn(options); when(webDriver.switchTo()).thenReturn(locator); when(locator.alert()).thenReturn(alert); when(alert.getText()).thenReturn("Hello!"); when(webDriver.findElement(By.id("header"))).thenReturn(element); when(element.getTagName()).thenReturn("h1"); when(element.isEnabled()).thenReturn(true); when(element.isDisplayed()).thenReturn(true); when(webDriver.findElement(By.linkText("Click Me!"))).thenReturn(link); when(link.getTagName()).thenReturn("a"); when(link.isEnabled()).thenReturn(true); when(link.isDisplayed()).thenReturn(true); when(webDriver.findElement(By.linkText("Hover Me!"))).thenReturn(link); when(webDriver.getMouse()).thenReturn(mouse); when(webDriver.getKeyboard()).thenReturn(keyboard); when(link.getCoordinates()).thenReturn(coordinates); when(webDriver.findElement(By.name("username"))).thenReturn(input); when(input.getTagName()).thenReturn("input"); when(input.isEnabled()).thenReturn(true); when(input.isDisplayed()).thenReturn(true); when(webDriver.findElement(By.name("hiddenButton"))).thenReturn(hidden); when(hidden.getTagName()).thenReturn("input"); when(hidden.isEnabled()).thenReturn(true); when(hidden.isDisplayed()).thenReturn(false); when(webDriver.findElement(By.xpath("//input[@type='checkbox']"))).thenReturn(checkbox); when(checkbox.getTagName()).thenReturn("input"); when(checkbox.isEnabled()).thenReturn(true); when(checkbox.isDisplayed()).thenReturn(true); when(checkbox.isSelected()).thenReturn(false); when(webDriver.executeScript(anyString())).thenReturn(Collections.singletonList("This went wrong!")); when(webDriver.findElement(By.className("btn"))).thenReturn(button); when(button.getTagName()).thenReturn("button"); when(button.isEnabled()).thenReturn(false); when(button.isDisplayed()).thenReturn(false); when(button.getText()).thenReturn("Click Me!"); when(button.getAttribute("type")).thenReturn("submit"); when(button.getCssValue("color")).thenReturn("red"); when(seleniumBrowser.getStoredFile("file.txt")).thenReturn("file.txt"); Set<String> windows = new HashSet<>(); windows.add("last_window"); windows.add("new_window"); when(webDriver.getWindowHandles()).thenReturn(Collections.singleton("last_window")).thenReturn(windows); when(webDriver.getWindowHandle()).thenReturn("last_window"); context.setApplicationContext(applicationContextMock); context.setVariable("cssClass", "btn"); MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContextMock, context) { @Override//ww w. j a va 2s. c o m public void execute() { selenium(action -> action.start(seleniumBrowser)); selenium(action -> action.navigate("http://localhost:9090")); selenium(action -> action.find().element(By.id("header"))); selenium(action -> action.find().element("class-name", "${cssClass}").tagName("button") .enabled(false).displayed(false).text("Click Me!").style("color", "red") .attribute("type", "submit")); selenium(action -> action.click().element(By.linkText("Click Me!"))); selenium(action -> action.hover().element(By.linkText("Hover Me!"))); selenium(action -> action.setInput("Citrus").element(By.name("username"))); selenium(action -> action.checkInput(false).element(By.xpath("//input[@type='checkbox']"))); selenium(action -> action.javascript("alert('Hello!')").errors("This went wrong!")); selenium(action -> action.alert().text("Hello!").accept()); selenium(action -> action.clearCache()); selenium(action -> action.store("classpath:download/file.txt")); selenium(action -> action.getStored("file.txt")); selenium(action -> action.open().window("my_window")); selenium(action -> action.focus().window("my_window")); selenium(action -> action.close().window("my_window")); selenium(action -> action.waitUntil().hidden().element(By.name("hiddenButton"))); selenium(action -> action.stop()); } }; TestCase test = builder.getTestCase(); int actionIndex = 0; Assert.assertEquals(test.getActionCount(), 18); Assert.assertEquals(((DelegatingTestAction) test.getActions().get(actionIndex)).getDelegate().getClass(), StartBrowserAction.class); StartBrowserAction startBrowserAction = (StartBrowserAction) ((DelegatingTestAction) test.getActions() .get(actionIndex++)).getDelegate(); Assert.assertEquals(startBrowserAction.getName(), "selenium:start"); Assert.assertNotNull(startBrowserAction.getBrowser()); Assert.assertEquals(((DelegatingTestAction) test.getActions().get(actionIndex)).getDelegate().getClass(), NavigateAction.class); NavigateAction navigateAction = (NavigateAction) ((DelegatingTestAction) test.getActions() .get(actionIndex++)).getDelegate(); Assert.assertEquals(navigateAction.getName(), "selenium:navigate"); Assert.assertEquals(navigateAction.getPage(), "http://localhost:9090"); Assert.assertNotNull(navigateAction.getBrowser()); Assert.assertEquals(((DelegatingTestAction) test.getActions().get(actionIndex)).getDelegate().getClass(), FindElementAction.class); FindElementAction findElementAction = (FindElementAction) ((DelegatingTestAction) test.getActions() .get(actionIndex++)).getDelegate(); Assert.assertEquals(findElementAction.getName(), "selenium:find"); Assert.assertEquals(findElementAction.getBy(), By.id("header")); Assert.assertNotNull(findElementAction.getBrowser()); Assert.assertEquals(((DelegatingTestAction) test.getActions().get(actionIndex)).getDelegate().getClass(), FindElementAction.class); findElementAction = (FindElementAction) ((DelegatingTestAction) test.getActions().get(actionIndex++)) .getDelegate(); Assert.assertEquals(findElementAction.getName(), "selenium:find"); Assert.assertEquals(findElementAction.getProperty(), "class-name"); Assert.assertEquals(findElementAction.getPropertyValue(), "${cssClass}"); Assert.assertEquals(findElementAction.getTagName(), "button"); Assert.assertEquals(findElementAction.getText(), "Click Me!"); Assert.assertFalse(findElementAction.isEnabled()); Assert.assertFalse(findElementAction.isDisplayed()); Assert.assertEquals(findElementAction.getStyles().size(), 1L); Assert.assertEquals(findElementAction.getStyles().get("color"), "red"); Assert.assertEquals(findElementAction.getAttributes().size(), 1L); Assert.assertEquals(findElementAction.getAttributes().get("type"), "submit"); Assert.assertNotNull(findElementAction.getBrowser()); Assert.assertEquals(((DelegatingTestAction) test.getActions().get(actionIndex)).getDelegate().getClass(), ClickAction.class); ClickAction clickAction = (ClickAction) ((DelegatingTestAction) test.getActions().get(actionIndex++)) .getDelegate(); Assert.assertEquals(clickAction.getName(), "selenium:click"); Assert.assertEquals(clickAction.getBy(), By.linkText("Click Me!")); Assert.assertNotNull(findElementAction.getBrowser()); Assert.assertEquals(((DelegatingTestAction) test.getActions().get(actionIndex)).getDelegate().getClass(), HoverAction.class); HoverAction hoverAction = (HoverAction) ((DelegatingTestAction) test.getActions().get(actionIndex++)) .getDelegate(); Assert.assertEquals(hoverAction.getName(), "selenium:hover"); Assert.assertEquals(hoverAction.getBy(), By.linkText("Hover Me!")); Assert.assertNotNull(findElementAction.getBrowser()); Assert.assertEquals(((DelegatingTestAction) test.getActions().get(actionIndex)).getDelegate().getClass(), SetInputAction.class); SetInputAction setInputAction = (SetInputAction) ((DelegatingTestAction) test.getActions() .get(actionIndex++)).getDelegate(); Assert.assertEquals(setInputAction.getName(), "selenium:set-input"); Assert.assertEquals(setInputAction.getBy(), By.name("username")); Assert.assertEquals(setInputAction.getValue(), "Citrus"); Assert.assertNotNull(findElementAction.getBrowser()); Assert.assertEquals(((DelegatingTestAction) test.getActions().get(actionIndex)).getDelegate().getClass(), CheckInputAction.class); CheckInputAction checkInputAction = (CheckInputAction) ((DelegatingTestAction) test.getActions() .get(actionIndex++)).getDelegate(); Assert.assertEquals(checkInputAction.getName(), "selenium:check-input"); Assert.assertEquals(checkInputAction.getBy(), By.xpath("//input[@type='checkbox']")); Assert.assertFalse(checkInputAction.isChecked()); Assert.assertNotNull(findElementAction.getBrowser()); Assert.assertEquals(((DelegatingTestAction) test.getActions().get(actionIndex)).getDelegate().getClass(), JavaScriptAction.class); JavaScriptAction javaScriptAction = (JavaScriptAction) ((DelegatingTestAction) test.getActions() .get(actionIndex++)).getDelegate(); Assert.assertEquals(javaScriptAction.getName(), "selenium:javascript"); Assert.assertEquals(javaScriptAction.getScript(), "alert('Hello!')"); Assert.assertEquals(javaScriptAction.getExpectedErrors().size(), 1L); Assert.assertEquals(javaScriptAction.getExpectedErrors().get(0), "This went wrong!"); Assert.assertNotNull(findElementAction.getBrowser()); Assert.assertEquals(((DelegatingTestAction) test.getActions().get(actionIndex)).getDelegate().getClass(), AlertAction.class); AlertAction alertAction = (AlertAction) ((DelegatingTestAction) test.getActions().get(actionIndex++)) .getDelegate(); Assert.assertEquals(alertAction.getName(), "selenium:alert"); Assert.assertEquals(alertAction.getText(), "Hello!"); Assert.assertNotNull(findElementAction.getBrowser()); Assert.assertEquals(((DelegatingTestAction) test.getActions().get(actionIndex)).getDelegate().getClass(), ClearBrowserCacheAction.class); ClearBrowserCacheAction clearBrowserCacheAction = (ClearBrowserCacheAction) ((DelegatingTestAction) test .getActions().get(actionIndex++)).getDelegate(); Assert.assertEquals(clearBrowserCacheAction.getName(), "selenium:clear-cache"); Assert.assertNotNull(findElementAction.getBrowser()); Assert.assertEquals(((DelegatingTestAction) test.getActions().get(actionIndex)).getDelegate().getClass(), StoreFileAction.class); StoreFileAction storeFileAction = (StoreFileAction) ((DelegatingTestAction) test.getActions() .get(actionIndex++)).getDelegate(); Assert.assertEquals(storeFileAction.getName(), "selenium:store-file"); Assert.assertEquals(storeFileAction.getFilePath(), "classpath:download/file.txt"); Assert.assertNotNull(findElementAction.getBrowser()); Assert.assertEquals(((DelegatingTestAction) test.getActions().get(actionIndex)).getDelegate().getClass(), GetStoredFileAction.class); GetStoredFileAction getStoredFileAction = (GetStoredFileAction) ((DelegatingTestAction) test.getActions() .get(actionIndex++)).getDelegate(); Assert.assertEquals(getStoredFileAction.getName(), "selenium:get-stored-file"); Assert.assertEquals(getStoredFileAction.getFileName(), "file.txt"); Assert.assertNotNull(findElementAction.getBrowser()); Assert.assertEquals(((DelegatingTestAction) test.getActions().get(actionIndex)).getDelegate().getClass(), OpenWindowAction.class); OpenWindowAction openWindowAction = (OpenWindowAction) ((DelegatingTestAction) test.getActions() .get(actionIndex++)).getDelegate(); Assert.assertEquals(openWindowAction.getName(), "selenium:open-window"); Assert.assertEquals(openWindowAction.getWindowName(), "my_window"); Assert.assertNotNull(findElementAction.getBrowser()); Assert.assertEquals(((DelegatingTestAction) test.getActions().get(actionIndex)).getDelegate().getClass(), SwitchWindowAction.class); SwitchWindowAction switchWindowAction = (SwitchWindowAction) ((DelegatingTestAction) test.getActions() .get(actionIndex++)).getDelegate(); Assert.assertEquals(switchWindowAction.getName(), "selenium:switch-window"); Assert.assertEquals(switchWindowAction.getWindowName(), "my_window"); Assert.assertNotNull(findElementAction.getBrowser()); Assert.assertEquals(((DelegatingTestAction) test.getActions().get(actionIndex)).getDelegate().getClass(), CloseWindowAction.class); CloseWindowAction closeWindowAction = (CloseWindowAction) ((DelegatingTestAction) test.getActions() .get(actionIndex++)).getDelegate(); Assert.assertEquals(closeWindowAction.getName(), "selenium:close-window"); Assert.assertEquals(closeWindowAction.getWindowName(), "my_window"); Assert.assertNotNull(findElementAction.getBrowser()); Assert.assertEquals(((DelegatingTestAction) test.getActions().get(actionIndex)).getDelegate().getClass(), WaitUntilAction.class); WaitUntilAction waitUntilAction = (WaitUntilAction) ((DelegatingTestAction) test.getActions() .get(actionIndex++)).getDelegate(); Assert.assertEquals(waitUntilAction.getName(), "selenium:wait"); Assert.assertEquals(waitUntilAction.getBy(), By.name("hiddenButton")); Assert.assertEquals(waitUntilAction.getCondition(), "hidden"); Assert.assertNotNull(findElementAction.getBrowser()); Assert.assertEquals(((DelegatingTestAction) test.getActions().get(actionIndex)).getDelegate().getClass(), StopBrowserAction.class); StopBrowserAction stopBrowserAction = (StopBrowserAction) ((DelegatingTestAction) test.getActions() .get(actionIndex++)).getDelegate(); Assert.assertEquals(stopBrowserAction.getName(), "selenium:stop"); Assert.assertNotNull(stopBrowserAction.getBrowser()); Assert.assertEquals(context.getVariable(SeleniumHeaders.SELENIUM_ALERT_TEXT), "Hello!"); Assert.assertEquals(context.getVariable(SeleniumHeaders.SELENIUM_DOWNLOAD_FILE), "file.txt"); Assert.assertEquals(context.getVariable(SeleniumHeaders.SELENIUM_LAST_WINDOW), "last_window"); Assert.assertEquals(context.getVariable(SeleniumHeaders.SELENIUM_ACTIVE_WINDOW), "new_window"); Assert.assertEquals(context.getVariable("my_window"), "new_window"); verify(alert).accept(); verify(options).deleteAllCookies(); verify(link).click(); verify(input).clear(); verify(input).sendKeys("Citrus"); }
From source file:com.consol.citrus.selenium.actions.FindElementAction.java
License:Apache License
/** * Create by selector from type information. * @return/*from w ww. j a v a2 s.c o m*/ */ protected By createBy(TestContext context) { if (by != null) { return by; } switch (property) { case "id": return By.id(context.replaceDynamicContentInString(propertyValue)); case "class-name": return By.className(context.replaceDynamicContentInString(propertyValue)); case "link-text": return By.linkText(context.replaceDynamicContentInString(propertyValue)); case "css-selector": return By.cssSelector(context.replaceDynamicContentInString(propertyValue)); case "name": return By.name(context.replaceDynamicContentInString(propertyValue)); case "tag-name": return By.tagName(context.replaceDynamicContentInString(propertyValue)); case "xpath": return By.xpath(context.replaceDynamicContentInString(propertyValue)); } throw new CitrusRuntimeException("Unknown selector type: " + property); }
From source file:com.consol.citrus.selenium.actions.FindElementActionTest.java
License:Apache License
@DataProvider public Object[][] findByProvider() { return new Object[][] { new Object[] { "id", "myId", By.id("myId") }, new Object[] { "name", "myName", By.name("myName") }, new Object[] { "tag-name", "button", By.tagName("button") }, new Object[] { "class-name", "myClass", By.className("myClass") }, new Object[] { "link-text", "myLinkText", By.linkText("myLinkText") }, new Object[] { "css-selector", "myCss", By.cssSelector("myCss") }, new Object[] { "xpath", "myXpath", By.xpath("myXpath") } }; }
From source file:com.consol.citrus.selenium.client.WebClient.java
License:Apache License
public static By getByFromEnum(ByEnum byEnum, String select) { By by = null;//from ww w. jav a2 s . co m switch (byEnum) { case ID: by = By.id(select); break; case CLASS_NAME: by = By.className(select); break; case LINK_TEXT: by = By.linkText(select); break; case CSS_SELECTOR: by = By.cssSelector(select); break; case NAME: by = By.name(select); break; case TAG_NAME: by = By.tagName(select); break; case XPATH: by = By.xpath(select); break; } return by; }
From source file:com.constellio.sdk.tests.selenium.adapters.base.WebDriverAdapter.java
License:Open Source License
public WE find(String className) { return findElement(By.className(className)); }
From source file:com.daarons.transfer.DownloadTask.java
License:Apache License
private void acceptToS() { try {/*from w w w . j a v a 2s .c om*/ WebElement acceptButton = smallWait .until(ExpectedConditions.presenceOfElementLocated(By.className("transfer__button"))); acceptButton.click(); } catch (Exception ex) { log.error("Couldn't accept ToS", ex); } }
From source file:com.daarons.transfer.DownloadTask.java
License:Apache License
private void enterPassword(String password) { WebElement passwordInput = driver.findElement( By.cssSelector("body > div > div > div.transfer > div > div.transfer__contents > div > input")); passwordInput.sendKeys(password);//w ww . j a v a 2s . co m WebElement enterPasswordBtn = driver.findElement(By.className("transfer__button")); enterPasswordBtn.click(); }
From source file:com.daarons.transfer.DownloadTask.java
License:Apache License
private void clickDownloadButton() { WebElement downloadButton = smallWait .until(ExpectedConditions.presenceOfElementLocated(By.className("transfer__button"))); downloadButton.click();/*from w ww. j a v a 2 s . c o m*/ }