List of usage examples for org.openqa.selenium WebElement findElements
@Override List<WebElement> findElements(By by);
From source file:com.cloudbees.workflow.ui.view.StagePopupsTest.java
License:Open Source License
@Ignore("remove phantomjs: https://trello.com/c/JpUg8S5z/159-get-rid-of-phantomjs-webdriver") @Test// w w w . ja v a2 s . c o m public void test() throws Exception { WebDriver webdriver = getWebDriver(); WorkflowJob job = jenkinsRule.jenkins.createProject(WorkflowJob.class, "Noddy Job"); job.setDefinition(new CpsFlowDefinition( "" + "node {" + " stage ('Build'); " + " sh ('ls'); " + " sh ('blah'); " + "}")); QueueTaskFuture<WorkflowRun> build = job.scheduleBuild2(0); jenkinsRule.assertBuildStatus(Result.FAILURE, build.get()); String jobUrl = getItemUrl(jenkinsRule.jenkins, job); webdriver.get(jobUrl); // Make sure the stage cell was marked as failed... List<WebElement> failedStageCells = webdriver .findElements(By.cssSelector(".stage-cell.FAILED .stage-wrapper")); Assert.assertEquals(1, failedStageCells.size()); // Make the sure the stage-failed-popover widget was added to the cell WebElement failedStageCell = failedStageCells.get(0); List<WebElement> stageFailedPopovers = failedStageCell .findElements(By.cssSelector(".stage-failed-popover")); Assert.assertEquals(1, stageFailedPopovers.size()); // Make sure that when we mouse over the failed stage cell we get a popup... moveMouseToElement(webdriver, failedStageCell); List<WebElement> popovers = waitForElementsAdded(webdriver, ".cbwf-popover"); Assert.assertTrue(popovers.size() > 0); Assert.assertEquals("Failed with the following error(s)\n" + "Shell Script script returned exit code 127\n" + "See stage logs for more detail.\n" + "Logs", popovers.get(0).getText().trim()); }
From source file:com.cloudbees.workflow.ui.view.WorkflowStageViewActionTest.java
License:Open Source License
@Ignore("remove phantomjs: https://trello.com/c/JpUg8S5z/159-get-rid-of-phantomjs-webdriver") @Test/*from w w w .j a v a 2 s. co m*/ public void test() throws Exception { WebDriver webdriver = getWebDriver(); WorkflowJob job = jenkinsRule.jenkins.createProject(WorkflowJob.class, "Noddy Job"); job.setDefinition(new CpsFlowDefinition("" + "node {" + " stage ('Build'); " + " sh ('echo Building'); " + " stage ('Test'); " + " sh ('echo Testing'); " + " stage ('Deploy'); " + " sh ('echo Deploying'); " + "}")); QueueTaskFuture<WorkflowRun> build = job.scheduleBuild2(0); jenkinsRule.assertBuildStatusSuccess(build); String jobUrl = getItemUrl(jenkinsRule.jenkins, job); webdriver.get(jobUrl); // System.out.println(webdriver.getPageSource()); // Make sure the jobsTable is rendered in the page WebElement jobsTable = webdriver.findElement(By.className("jobsTable")); Assert.assertNotNull(jobsTable); // Check the totals are rendered // List<WebElement> stageWrappers = jobsTable.findElements(By.cssSelector(".totals .stage-wrapper")); // Assert.assertEquals(3, stageWrappers.size()); // Should have just one job List<WebElement> jobs = jobsTable.findElements(By.cssSelector(".job")); Assert.assertEquals(1, jobs.size()); // That job should have 3 stages List<WebElement> jobStages = jobs.get(0).findElements(By.cssSelector(".stage-wrapper")); Assert.assertEquals(3, jobStages.size()); }
From source file:com.coderoad.automation.common.util.PageUtil.java
License:Open Source License
/** * Gets the elements by sub element.// w ww .j av a 2s.c o m * * @param driver the driver * @param element the element * @param locator the locator * @param timeout the timeout * @return the elements by sub element */ public static List<WebElement> getElementsBySubElement(final WebDriver driver, final WebElement element, final By locator, Timeout timeout) { try { return new WebDriverWait(driver, timeout.getValue()).until(new ExpectedCondition<List<WebElement>>() { public List<WebElement> apply(final WebDriver driver) { if (element.findElement(locator) != null) { return element.findElements(locator); } return null; } }); } catch (Exception e) { return null; } }
From source file:com.coderoad.automation.common.util.PageUtil.java
License:Open Source License
/** * Method to set date in a date picker//from w w w . j a va 2 s.com * @author Ruth Chirinos * @param driver the WebDriver * @param xpathDatePicker the xpath of the datePicker * @param vehicleSelectionPage * year - the year minus 1900. * month - the month between 0-11. * date - the day of the month between 1-31. * @throws InterruptedException * @throws ParseException */ public static boolean setDateInDatePicker(WebDriver driver, String xpathDatePicker, Date dateRequested) throws InterruptedException, ParseException { Calendar dateRequestedCalendar = DateUtil.getCalendarForDate(dateRequested); LogUtil.log("Date for changing is > " + DateUtil.format(dateRequestedCalendar, DateUtil.DATE_MONTH_ABBREVIATION), LogLevel.LOW); boolean processOk = false; String dateSelectedString = ""; Date dateSelected = null; SimpleDateFormat simpleFormat = new SimpleDateFormat(DateUtil.DATE_MONTH_YEAR_FMT); WebElement datePicker = driver.findElement(By.xpath(xpathDatePicker)); datePicker.click(); WebElement monthYearElement = driver .findElement(By.xpath("//div[@class='x-datepicker-month']/div/div/a/span[1]")); WebElement daySelected = driver.findElement(By.xpath("//*[contains(@class, 'x-datepicker-selected')]/a")); dateSelectedString = daySelected.getAttribute("innerHTML") + " " + monthYearElement.getAttribute("innerHTML"); dateSelected = simpleFormat.parse(dateSelectedString); WebElement pickerPrevEl = driver.findElement( By.xpath("//div[@class='x-datepicker-header']/a[contains(@class, 'x-datepicker-prev')]")); WebElement pickerNextEl = driver.findElement( By.xpath("//div[@class='x-datepicker-header']/a[contains(@class, 'x-datepicker-next')]")); //Choosing the year while (dateRequested.getYear() < dateSelected.getYear()) { pickerPrevEl.click(); monthYearElement = driver.findElement(By.xpath("//div[@class='x-datepicker-month']/div/div/a/span[1]")); dateSelectedString = daySelected.getAttribute("innerHTML") + " " + monthYearElement.getAttribute("innerHTML"); dateSelected = simpleFormat.parse(dateSelectedString); } while (dateRequested.getYear() > dateSelected.getYear()) { pickerNextEl.click(); monthYearElement = driver.findElement(By.xpath("//div[@class='x-datepicker-month']/div/div/a/span[1]")); dateSelectedString = daySelected.getAttribute("innerHTML") + " " + monthYearElement.getAttribute("innerHTML"); dateSelected = simpleFormat.parse(dateSelectedString); } //Choosing the months while (dateRequested.getMonth() < dateSelected.getMonth()) { pickerPrevEl.click(); monthYearElement = driver.findElement(By.xpath("//div[@class='x-datepicker-month']/div/div/a/span[1]")); dateSelectedString = daySelected.getAttribute("innerHTML") + " " + monthYearElement.getAttribute("innerHTML"); dateSelected = simpleFormat.parse(dateSelectedString); } while (dateRequested.getMonth() > dateSelected.getMonth()) { pickerNextEl.click(); monthYearElement = driver.findElement(By.xpath("//div[@class='x-datepicker-month']/div/div/a/span[1]")); dateSelectedString = daySelected.getAttribute("innerHTML") + " " + monthYearElement.getAttribute("innerHTML"); dateSelected = simpleFormat.parse(dateSelectedString); } //Choosing the day WebElement dateWidget = driver.findElement(By.className("x-datepicker-inner")); List<WebElement> columns = dateWidget.findElements(By.tagName("td")); int aux = 0; for (WebElement cell : columns) { if (cell.getText().equals(dateRequested.getDate() + "")) { processOk = cell.getAttribute("class").contains("x-datepicker-active"); if (processOk) { cell.findElement(By.tagName("a")).click(); ; LogUtil.log("The date was selected.", LogLevel.LOW); aux = 1; break; } } } if (aux == 0) { LogUtil.log("The date selected is not enabled.", LogLevel.LOW); } return processOk; }
From source file:com.cognifide.qa.bb.aem.core.component.dialog.DialogFieldRetrieverImpl.java
License:Apache License
private List<WebElement> getFields(WebElement parentElement, String type) { List<WebElement> toReturn; switch (type) { case Fields.IMAGE: toReturn = parentElement.findElements(IMAGE_LOCATOR); break;//from w w w . jav a2s. c o m case Fields.CHECKBOX: toReturn = parentElement.findElements(CHECKBOX_LOCATOR); break; case Fields.RADIO_GROUP_MULTI: toReturn = parentElement.findElements(RADIO_GROUP_LOCATOR); break; default: toReturn = parentElement.findElements(FIELD_LOCATOR); break; } return toReturn; }
From source file:com.cognifide.qa.bb.aem.core.component.dialog.DialogFieldRetrieverImpl.java
License:Apache License
/** * Returns the label of given field. Label may not be present in the field, thus a workaround * using list is introduced here./*from w w w .ja v a2 s . c om*/ * * @param field WebElement corresponding to the given field * @return label of the field or {@code StringUtils.Empty} when there is none */ private String getFieldLabel(WebElement field, String type) { List<WebElement> labelField = type.equals(Fields.CHECKBOX) ? field.findElements(CHECKBOX_LABEL_SELECTOR) : field.findElements(LABEL_SELECTOR); return labelField.isEmpty() ? StringUtils.EMPTY : labelField.get(0).getText(); }
From source file:com.cognifide.qa.bb.aem.core.sidepanel.internal.ComponentTreeLocatorHelper.java
License:Apache License
private static WebElement setComponent(WebElement component, String container) { List<WebElement> elements = component.findElements(By.className("coral3-Tree-item--drilldown")); if (!elements.isEmpty()) { return elements.get(calculateElementNumber(container)); }/*w w w. j ava 2 s. c o m*/ return component; }
From source file:com.cognifide.qa.bb.aem.touch.pageobjects.touchui.DialogConfigurer.java
License:Apache License
/** * Finds the dialog field of given type within a WebElement based on the provided label. If label is not * present, returns the first field from the tab. * * @param parentElement parent element from which DialogField will be retrieved * @param label of the requested field * @param type of the requested field * @return DialogField of the given type based on the provided info *///w w w . j a v a2 s . co m public DialogField getDialogField(WebElement parentElement, String label, String type) { List<WebElement> fields = parentElement.findElements(FIELD_LOCATOR); if (fields.isEmpty()) { throw new IllegalStateException("There are no fields in the tab"); } WebElement scope = StringUtils.isEmpty(label) ? fields.get(0) : fields.stream() // .filter(field -> containsIgnoreCase(getFieldLabel(field), label)) // .findFirst() // .orElseThrow(() -> new IllegalStateException("Dialog field not found")); return getFieldObject(scope, type); }
From source file:com.cognifide.qa.bb.aem.touch.pageobjects.touchui.DialogConfigurer.java
License:Apache License
/** * Returns the label of given field./*from www . jav a 2 s .com*/ * Label may not be present in the field, thus a workaround using list is introduced here. * * @param field WebElement corresponding to the given field * @return label of the field or {@code StringUtils.Empty} when there is none */ private String getFieldLabel(WebElement field) { List<WebElement> labelField = field.findElements(LABEL_SELECTOR); return labelField.isEmpty() ? StringUtils.EMPTY : labelField.get(0).getText(); }
From source file:com.cognifide.qa.bb.aem.ui.AemDialog.java
License:Apache License
/** * Finds the dialog tab by its index and returns its name (label). * * @param index of the tab (starts from 0) * @return Tab's label./*ww w. j a v a 2s. c o m*/ */ public String getLabelFromTab(int index) { WebElement dialog = webDriver.findElement(DIALOG_XPATH_COMPILED); List<WebElement> items = dialog.findElements(By.className("x-tab-item")); WebElement widget = items.get(index); WebElement label = widget.findElement(By.xpath(".//label")); return label.getText(); }