List of usage examples for org.openqa.selenium.support.ui ExpectedConditions presenceOfAllElementsLocatedBy
public static ExpectedCondition<List<WebElement>> presenceOfAllElementsLocatedBy(final By locator)
From source file:org.jboss.forge.scaffold.angularjs.scenario.dronetests.onetoonerequired.AddressAndRequiredCustomerViewsClient.java
License:Open Source License
@Test @InSequence(1)// w ww. j av a2 s . co m public void testSaveNewAddress(@ArquillianResource URL baseUrl) throws Exception { Wait<WebDriver> wait = new WebDriverWait(driver, 10); // Click on the Address nav entry driver.get(baseUrl.toString() + "app.html#/"); driver.findElement(By.linkText("Addresss")).click(); wait.until(new HasLandedOnSearchAddressView()); // Choose to create a new address driver.findElement(By.id("Create")).click(); wait.until(new HasLandedOnNewAddressView()); // Enter the address details and save driver.findElement(By.id("street")).clear(); driver.findElement(By.id("street")).sendKeys("6747 Crystal Limits"); driver.findElement(By.id("city")).clear(); driver.findElement(By.id("city")).sendKeys("Markinch"); driver.findElement(By.id("state")).clear(); driver.findElement(By.id("state")).sendKeys("Mississippi"); driver.findElement(By.id("country")).clear(); driver.findElement(By.id("country")).sendKeys("USA"); driver.findElement(By.id("postalcode")).clear(); driver.findElement(By.id("postalcode")).sendKeys("39512-8569"); driver.findElement(By.id("saveAddress")).click(); // Verify the details are presented in the Edit view wait.until(new HasLandedOnEditAddressView()); assertEquals(baseUrl.toString() + "app.html#/Addresss/edit/1", driver.getCurrentUrl()); assertEquals("6747 Crystal Limits", driver.findElement(By.id("street")).getAttribute("value")); assertEquals("Markinch", driver.findElement(By.id("city")).getAttribute("value")); assertEquals("Mississippi", driver.findElement(By.id("state")).getAttribute("value")); assertEquals("USA", driver.findElement(By.id("country")).getAttribute("value")); assertEquals("39512-8569", driver.findElement(By.id("postalcode")).getAttribute("value")); // Browse to search customer view and verify if searching for the customer works driver.findElement(By.id("cancel")).click(); wait.until(new HasLandedOnSearchAddressView()); driver.findElement(By.id("street")).clear(); driver.findElement(By.id("street")).sendKeys("6747"); wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("id(\"search-results-body\")/tr"))); List<WebElement> searchResults = driver.findElements(By.xpath("id(\"search-results-body\")/tr")); assertEquals(1, searchResults.size()); // Browse to the edit View of a search result and verify if the details are displayed driver.findElement(By.xpath("id(\"search-results-body\")/tr[1]/td[1]/a")).click(); wait.until(new HasLandedOnEditAddressView()); assertEquals("6747 Crystal Limits", driver.findElement(By.id("street")).getAttribute("value")); assertEquals("Markinch", driver.findElement(By.id("city")).getAttribute("value")); assertEquals("Mississippi", driver.findElement(By.id("state")).getAttribute("value")); assertEquals("USA", driver.findElement(By.id("country")).getAttribute("value")); assertEquals("39512-8569", driver.findElement(By.id("postalcode")).getAttribute("value")); // Edit the details, save and reverify the details driver.findElement(By.id("street")).clear(); driver.findElement(By.id("street")).sendKeys("6017 Thunder Way"); driver.findElement(By.id("city")).clear(); driver.findElement(By.id("city")).sendKeys("Skookumchuck"); driver.findElement(By.id("postalcode")).clear(); driver.findElement(By.id("postalcode")).sendKeys("39200-1131"); driver.findElement(By.id("saveAddress")).click(); wait.until(new HasLandedOnEditAddressView()); assertEquals("6017 Thunder Way", driver.findElement(By.id("street")).getAttribute("value")); assertEquals("Skookumchuck", driver.findElement(By.id("city")).getAttribute("value")); assertEquals("Mississippi", driver.findElement(By.id("state")).getAttribute("value")); assertEquals("USA", driver.findElement(By.id("country")).getAttribute("value")); assertEquals("39200-1131", driver.findElement(By.id("postalcode")).getAttribute("value")); }
From source file:org.jboss.forge.scaffold.angularjs.scenario.dronetests.onetoonerequired.AddressAndRequiredCustomerViewsClient.java
License:Open Source License
@Test @InSequence(2)/*from w ww. ja v a2 s. c o m*/ public void testSaveNewCustomer(@ArquillianResource URL baseUrl) throws Exception { Wait<WebDriver> wait = new WebDriverWait(driver, 10); // Click on the Customers nav entry driver.get(baseUrl.toString() + "app.html#/"); driver.findElement(By.linkText("Customers")).click(); wait.until(new HasLandedOnSearchCustomerView()); // Choose to create a new customer driver.findElement(By.id("Create")).click(); wait.until(new HasLandedOnNewCustomerView()); // Enter the customer details driver.findElement(By.id("firstName")).clear(); driver.findElement(By.id("firstName")).sendKeys("John Doe"); driver.findElement(By.id("dateOfBirth")).clear(); driver.findElement(By.id("dateOfBirth")).sendKeys("2013-01-10"); // Verify that the shipping Address field is marked as required before filling isBootstrapErrorDisplayedForFormControl("shippingAddressControls", "required"); // Establish the customer and address relationship WebElement addressElement = driver.findElement(By.id("shippingAddress")); Select addresses = new Select(addressElement); addresses.selectByVisibleText("1"); // Save driver.findElement(By.id("saveCustomer")).click(); // Verify the details are presented in the Edit view wait.until(new HasLandedOnEditCustomerView()); assertEquals(baseUrl.toString() + "app.html#/Customers/edit/2", driver.getCurrentUrl()); assertEquals("John Doe", driver.findElement(By.id("firstName")).getAttribute("value")); assertEquals("2013-01-10", driver.findElement(By.id("dateOfBirth")).getAttribute("value")); addressElement = driver.findElement(By.id("shippingAddress")); addresses = new Select(addressElement); assertEquals("1", addresses.getFirstSelectedOption().getText()); // Browse to search customer view and verify if searching for the customer works driver.findElement(By.id("cancel")).click(); wait.until(new HasLandedOnSearchCustomerView()); driver.findElement(By.id("firstName")).clear(); driver.findElement(By.id("firstName")).sendKeys("John"); wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("id(\"search-results-body\")/tr"))); List<WebElement> searchResults = driver.findElements(By.xpath("id(\"search-results-body\")/tr")); assertEquals(1, searchResults.size()); // Browse to the edit View of a search result and verify if the details are displayed driver.findElement(By.xpath("id(\"search-results-body\")/tr[1]/td[1]/a")).click(); wait.until(new HasLandedOnEditCustomerView()); assertEquals("John Doe", driver.findElement(By.id("firstName")).getAttribute("value")); assertEquals("2013-01-10", driver.findElement(By.id("dateOfBirth")).getAttribute("value")); addressElement = driver.findElement(By.id("shippingAddress")); addresses = new Select(addressElement); assertEquals("1", addresses.getFirstSelectedOption().getText()); // Edit the details, save and reverify the details driver.findElement(By.id("firstName")).clear(); driver.findElement(By.id("firstName")).sendKeys("Jane Doe"); driver.findElement(By.id("saveCustomer")).click(); wait.until(new HasLandedOnEditCustomerView()); assertEquals("Jane Doe", driver.findElement(By.id("firstName")).getAttribute("value")); assertEquals("2013-01-10", driver.findElement(By.id("dateOfBirth")).getAttribute("value")); addressElement = driver.findElement(By.id("shippingAddress")); addresses = new Select(addressElement); assertEquals("1", addresses.getFirstSelectedOption().getText()); // Browse to search customer view and verify if searching for the customer works driver.findElement(By.id("cancel")).click(); wait.until(new HasLandedOnSearchCustomerView()); addressElement = driver.findElement(By.id("shippingAddress")); addresses = new Select(addressElement); addresses.selectByVisibleText("1"); wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("id(\"search-results-body\")/tr"))); searchResults = driver.findElements(By.xpath("id(\"search-results-body\")/tr")); assertEquals(1, searchResults.size()); }
From source file:org.jboss.forge.scaffold.angularjs.scenario.dronetests.singleentity.CustomerViewClient.java
License:Open Source License
@Test public void testSaveNewCustomer(@ArquillianResource URL baseUrl) throws Exception { Wait<WebDriver> wait = new WebDriverWait(driver, 10); // Click on the Customers nav entry driver.get(baseUrl.toString() + "app.html#/"); driver.findElement(By.linkText("Customers")).click(); wait.until(new HasLandedOnSearchCustomerView()); // Choose to create a new customer driver.findElement(By.id("Create")).click(); wait.until(new HasLandedOnNewCustomerView()); // Enter the customer details and save driver.findElement(By.id("firstName")).clear(); driver.findElement(By.id("firstName")).sendKeys("John Doe"); driver.findElement(By.id("dateOfBirth")).clear(); driver.findElement(By.id("dateOfBirth")).sendKeys("2013-01-10"); driver.findElement(By.id("saveCustomer")).click(); // Verify the details are presented in the Edit view wait.until(new HasLandedOnEditCustomerView()); assertEquals(baseUrl.toString() + "app.html#/Customers/edit/1", driver.getCurrentUrl()); assertEquals("John Doe", driver.findElement(By.id("firstName")).getAttribute("value")); assertEquals("2013-01-10", driver.findElement(By.id("dateOfBirth")).getAttribute("value")); // Browse to search customer view and verify if searching for the customer works driver.findElement(By.id("cancel")).click(); wait.until(new HasLandedOnSearchCustomerView()); driver.findElement(By.id("firstName")).clear(); driver.findElement(By.id("firstName")).sendKeys("John"); wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("id(\"search-results-body\")/tr"))); List<WebElement> searchResults = driver.findElements(By.xpath("id(\"search-results-body\")/tr")); assertEquals(1, searchResults.size()); // Browse to the edit View of a search result and verify if the details are displayed driver.findElement(By.xpath("id(\"search-results-body\")/tr[1]/td[1]/a")).click(); wait.until(new HasLandedOnEditCustomerView()); assertEquals("John Doe", driver.findElement(By.id("firstName")).getAttribute("value")); assertEquals("2013-01-10", driver.findElement(By.id("dateOfBirth")).getAttribute("value")); // Edit the details, save and reverify the details driver.findElement(By.id("firstName")).clear(); driver.findElement(By.id("firstName")).sendKeys("Jane Doe"); driver.findElement(By.id("saveCustomer")).click(); wait.until(new HasLandedOnEditCustomerView()); assertEquals("Jane Doe", driver.findElement(By.id("firstName")).getAttribute("value")); assertEquals("2013-01-10", driver.findElement(By.id("dateOfBirth")).getAttribute("value")); }
From source file:org.jboss.forge.scaffold.angularjs.scenario.dronetests.singleentityvalidations.CustomerViewWithValidationsClient.java
License:Open Source License
@Test public void testSaveNewCustomer(@ArquillianResource URL baseUrl) throws Exception { Wait<WebDriver> wait = new WebDriverWait(driver, 10); // Click on the Customers nav entry driver.get(baseUrl.toString() + "app.html#/"); driver.findElement(By.linkText("Customers")).click(); wait.until(new HasLandedOnSearchCustomerView()); // Choose to create a new customer driver.findElement(By.id("Create")).click(); wait.until(new HasLandedOnNewCustomerView()); // Enter the customer details and save driver.findElement(By.id("firstName")).clear(); driver.findElement(By.id("firstName")).sendKeys("John Doe"); driver.findElement(By.id("dateOfBirth")).clear(); driver.findElement(By.id("dateOfBirth")).sendKeys("2013-01-10"); driver.findElement(By.id("ficoCreditScore")).clear(); driver.findElement(By.id("ficoCreditScore")).sendKeys("700"); driver.findElement(By.id("saveCustomer")).click(); // Verify the details are presented in the Edit view wait.until(new HasLandedOnEditCustomerView()); assertEquals(baseUrl.toString() + "app.html#/Customers/edit/1", driver.getCurrentUrl()); assertEquals("John Doe", driver.findElement(By.id("firstName")).getAttribute("value")); assertEquals("2013-01-10", driver.findElement(By.id("dateOfBirth")).getAttribute("value")); // Browse to search customer view and verify if searching for the customer works driver.findElement(By.id("cancel")).click(); wait.until(new HasLandedOnSearchCustomerView()); driver.findElement(By.id("firstName")).clear(); driver.findElement(By.id("firstName")).sendKeys("John"); wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("id(\"search-results-body\")/tr"))); List<WebElement> searchResults = driver.findElements(By.xpath("id(\"search-results-body\")/tr")); assertEquals(1, searchResults.size()); // Browse to the edit View of a search result and verify if the details are displayed driver.findElement(By.xpath("id(\"search-results-body\")/tr[1]/td[1]/a")).click(); wait.until(new HasLandedOnEditCustomerView()); assertEquals("John Doe", driver.findElement(By.id("firstName")).getAttribute("value")); assertEquals("2013-01-10", driver.findElement(By.id("dateOfBirth")).getAttribute("value")); // Edit the details, save and reverify the details driver.findElement(By.id("firstName")).clear(); driver.findElement(By.id("firstName")).sendKeys("Jane Doe"); driver.findElement(By.id("saveCustomer")).click(); wait.until(new HasLandedOnEditCustomerView()); assertEquals("Jane Doe", driver.findElement(By.id("firstName")).getAttribute("value")); assertEquals("2013-01-10", driver.findElement(By.id("dateOfBirth")).getAttribute("value")); }
From source file:org.mousephenotype.cda.selenium.GenePageTest.java
License:Apache License
/** * Tests that a sensible page is returned for an invalid gene id. * * @throws SolrServerException//from w w w. j av a 2 s .com */ @Test //@Ignore public void testInvalidGeneId() throws SolrServerException { RunStatus status = new RunStatus(); String testName = "testInvalidGeneId"; String target = ""; int targetCount = 1; String message; Date start = new Date(); String geneId = "junkBadGene"; final String EXPECTED_ERROR_MESSAGE = "Oops! The marker junkBadGene is not currently part of the IMPC project."; testUtils.logTestStartup(logger, this.getClass(), testName, targetCount, 1); boolean found = false; target = paBaseUrl + "/genes/" + geneId; System.out.println("URL: " + target); try { driver.get(target); List<WebElement> geneLinks = (new WebDriverWait(driver, timeoutInSeconds)) .until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.cssSelector("div.node h1"))); if (geneLinks == null) { message = "ERROR: Expected error page for MP_TERM_ID " + geneId + "(" + target + ") but found none."; status.addError(message); } for (WebElement element : geneLinks) { if (element.getText().compareTo(EXPECTED_ERROR_MESSAGE) == 0) { found = true; break; } } if (!found) { message = "ERROR: Expected error page for MGI_ACCESSION_ID " + geneId + "(" + target + ") but found none."; status.addError(message); } } catch (Exception e) { message = "EXCEPTION processing target URL " + target + ": " + e.getLocalizedMessage(); e.printStackTrace(); status.addError(message); } if (!status.hasErrors()) status.successCount++; testUtils.printEpilogue(testName, start, status, targetCount, 1); }
From source file:org.mousephenotype.cda.selenium.SearchPageTest.java
License:Apache License
@Test @Ignore/*from w w w . j a v a2s . c o m*/ public void testQueryingRandomGeneSymbols() throws TestException, JSONException { String testName = Thread.currentThread().getStackTrace()[1].getMethodName(); Date start = new Date(); RunStatus masterStatus = new RunStatus(); int nbRows = 20; testUtils.logTestStartup(logger, this.getClass(), testName, nbRows, nbRows); Random rn = new Random(); int startIndex = rn.nextInt(60000 - 0 + 1) + 1; String target = paBaseUrl + "/search#fq=*:*&facet=gene"; System.out.println("URL: " + target); String queryString = solrUrl + "/gene/select?q=*:*&start=" + startIndex + "&rows=" + nbRows + "&fl=marker_symbol&wt=json&indent=true"; JSONObject geneResults; try { geneResults = JSONRestUtil.getResults(queryString); } catch (Exception e) { throw new TestException("Error getting geneResults", e); } JSONArray docs = JSONRestUtil.getDocArray(geneResults); String message; if (docs != null) { int size = docs.length(); for (int i = 0; i < size; i++) { String geneSymbol1 = ""; try { geneSymbol1 = docs.getJSONObject(i).getString("marker_symbol"); SearchPage searchPage = new SearchPage(driver, timeoutInSeconds * 2, target, paBaseUrl, imageMap); searchPage.submitSearch(geneSymbol1); WebDriverWait localWait = new WebDriverWait(driver, 10); // Wait up to 10 seconds. localWait.until(ExpectedConditions .visibilityOfElementLocated(By.xpath("//ul[contains(@class, 'ui-autocomplete')]"))); List<WebElement> elems = localWait.until(ExpectedConditions.presenceOfAllElementsLocatedBy( By.cssSelector("ul#ui-id-1 li.ui-menu-item a span b.sugTerm"))); String geneSymbol2 = null; String autosuggestCandidates = ""; for (WebElement elem : elems) { String autosuggestGene = elem.getText(); if (!autosuggestCandidates.isEmpty()) autosuggestCandidates += ","; autosuggestCandidates += autosuggestGene; if (autosuggestGene.equals(geneSymbol1)) { geneSymbol2 = elem.getText(); break; } } if (geneSymbol1.trim().toLowerCase().equals(geneSymbol2.trim().toLowerCase())) { System.out.println("\tPASSED [" + geneSymbol1 + "]"); } else { message = "\tFAILED [" + geneSymbol1 + "]: Expected to find gene id '" + geneSymbol1 + "' in the autosuggest list but it was not found. URL: " + target; System.out.println(message); System.out.println( "\tWas searching for '" + geneSymbol1 + "' in [" + autosuggestCandidates + "]"); masterStatus.addError(message); } } catch (Exception e) { masterStatus .addError("ERROR testing gene symbol " + geneSymbol1 + ": " + e.getLocalizedMessage()); } } } if (!masterStatus.hasErrors()) masterStatus.successCount++; testUtils.printEpilogue(testName, start, masterStatus, nbRows, nbRows); }
From source file:org.mousephenotype.cda.selenium.support.GeneTable.java
License:Apache License
/** * * @return the number of rows in the "genes" table. Always include 1 extra for the heading. *//*from ww w . j a v a 2s. co m*/ private int computeTableRowCount() { // Wait for page. List<WebElement> elements = wait.until( ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("//table[@id='genes']/tbody/tr"))); return elements.size() + 1; }
From source file:org.mousephenotype.cda.selenium.support.GraphHeading.java
License:Apache License
/** * Parse the heading./*w ww .j a v a 2 s . c o m*/ */ private void parse(ChartType chartType) throws TestException { // Wait for all charts to load. wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy( By.xpath("//div[@class='section']/div[@class='inner']//div[@class='highcharts-container']"))); List<WebElement> titleElements = new ArrayList<>(); // Sometimes this times out. Try a few times before failing. boolean found = false; for (int i = 0; i < 15; i++) { titleElements = chartElement.findElements(By.xpath("./h2[@id='section-associations']")); if (titleElements.isEmpty()) { commonUtils.sleep(2000); continue; } else { found = true; break; } } if (!found) { throw new RuntimeException("GraphHeading.parse(): Wait to get chart timed out!"); } WebElement titleElement = titleElements.get(0); this.title = titleElement.getText().trim(); String rawAllele = title.replace("Allele - ", ""); List<WebElement> supElements = titleElement.findElements(By.xpath("./sup")); String sup = (supElements.isEmpty() ? "" : titleElement.findElement(By.xpath("./sup")).getText()); AlleleParser alleleParser = new AlleleParser(rawAllele, sup); Line1Parser line1Parser = new Line1Parser(); Line2Parser line2Parser = new Line2Parser(); ParameterParser parameterParser = new ParameterParser(chartType); this.alleleSymbol = alleleParser.toString(); this.geneticBackground = line1Parser.background; this.geneSymbol = alleleParser.gene; this.metadataGroup = line2Parser.metadataGroup; this.parameterName = parameterParser.getParameterName(); this.parameterStableId = parameterParser.getParameterStableId(); this.phenotypingCenter = line1Parser.phenotypingCenter; this.pipelineName = line1Parser.pipelineName; this.pipelineLinkElement = line1Parser.pipelineLinkElement; this.parameterObject = parameterParser.getParameterObject(); this.sopLinkElement = parameterParser.getSopLinkElement(); // Set the graph type from the parameterDAO. if (parameterObject != null) { observationType = impressUtils.checkType(parameterObject); } }
From source file:org.mousephenotype.cda.selenium.support.GraphPage.java
License:Apache License
/** * Load the page and its section and tsv/xls download data. */// w w w. java 2 s .c o m private void load() throws TestException { String message; List<WebElement> chartElements; List<WebElement> tableElements; // The wait is dependent on the chart icon type: postQcTable, postQcGraph, preqc String postQcXpathTable = "//div[@class='inner']/div[@id='histopath_wrapper']"; String postQcXpathChart = "//div[@class='chart']"; String preqcXpathOk = "//div[@class='viz-tools']"; String preqcXpathHung = "//div[@id='loading-app']"; List<WebElement> postQcTableElementList = driver.findElements(By.xpath(postQcXpathTable)); List<WebElement> postQcGraphElementList = driver.findElements(By.xpath(postQcXpathChart)); List<WebElement> preQcOkElementList = driver.findElements(By.xpath(preqcXpathOk)); List<WebElement> preQcHungElementList = driver.findElements(By.xpath(preqcXpathHung)); chartElements = new ArrayList<>(); tableElements = new ArrayList<>(); if (!postQcTableElementList.isEmpty()) { System.out.println("WAITING FOR postQcTable"); tableElements.addAll( wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath(postQcXpathTable)))); } if (!postQcGraphElementList.isEmpty()) { System.out.println("WAITING FOR postQcGraph"); chartElements.addAll( wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath(postQcXpathChart)))); } if (!preQcOkElementList.isEmpty()) { System.out.println("WAITING FOR preQcOk"); chartElements .addAll(wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath(preqcXpathOk)))); } // If the page is a chart, load the GraphSections. for (WebElement chartElement : chartElements) { GraphSection graphSection = GraphSectionFactory.createGraphSection(driver, wait, graphUrl, chartElement); graphSections.add(graphSection); } // If the page has download links, parse each download section into its // own DownloadSection. Each such section contains a map with two keys: // "tsv" and "xls". Each value points to its [tsv or xls] data. if (hasDownloadLinks()) { List<DownloadSection> downloadSections; try { downloadSections = loadAllDownloadData(); } catch (TestException te) { throw te; } catch (Exception e) { message = "Exception: " + e.getLocalizedMessage() + "\nURL: " + graphUrl; System.out.println(message); throw new TestException(message, e); } // For each GraphSection, compare the heading's pageKey with the set // of keys for each download section until found. If found, bind // that download section to the graph section; otherwise, throw an // exception indicating the expected key wasn't found. for (GraphSection graphSection : graphSections) { GraphHeading heading = graphSection.getHeading(); graphSection.setDownloadSection(null); String pageKey = heading.getMutantKey(); List<Set<String>> downloadKeysSet = new ArrayList(); for (DownloadSection downloadSection : downloadSections) { Set<String> downloadKeys = downloadSection.getKeys(heading.chartType, DownloadType.XLS); if (downloadKeys.contains(pageKey)) { graphSection.setDownloadSection(downloadSection); break; } else { downloadKeysSet.add(downloadKeys); } } if (graphSection.getDownloadSection() == null) { String setContents = ""; for (Set<String> downloadKeys : downloadKeysSet) { if (!setContents.isEmpty()) setContents += "\n\n"; setContents += testUtils.dumpSet(downloadKeys); } message = "ERROR: target " + graphUrl + "\nExpected page mutantKey '" + pageKey + "' but was not found. Set:\n" + setContents; System.out.println(message); throw new TestException(message); } } } }
From source file:org.mousephenotype.cda.selenium.support.GraphSection.java
License:Apache License
/** * Load the section data.// www .ja v a2 s . c o m */ private void load() throws TestException { try { String chartXpath = "//div[@class='section']/div[@class='inner']/div[@class='chart']"; wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath(chartXpath))); // Unidimensional box graphs sometimes aren't yet loaded when we get to this point. If this is one, wait for it to load. ChartType chartType = getChartType(chartElement); if (chartType == ChartType.UNIDIMENSIONAL_BOX_PLOT) { wait.until(ExpectedConditions .presenceOfAllElementsLocatedBy(By.xpath("//table[contains(@class, 'continuousTable')]"))); } List<WebElement> elements = chartElement .findElements(By.xpath(".//table[starts-with(@id, 'catTable')]")); if (!elements.isEmpty()) { this.catTable = new GraphCatTable(elements.get(0)); } for (int i = 0; i < 5; i++) { elements = chartElement.findElements(By.xpath("./table[starts-with(@class, 'continuousTable')]")); if (!elements.isEmpty()) { this.continuousTable = new GraphContinuousTable(elements.get(0)); break; } else { if ((elements.isEmpty()) && (chartType == ChartType.UNIDIMENSIONAL_BOX_PLOT)) { commonUtils.sleep(5000); } } } // Scrape this graph's data off the page. this.heading = new GraphHeading(chartElement, chartType, datasourceRepository, graphUrl, ontologyTermRepository, parameterRepository, wait); elements = chartElement .findElements(By.xpath("./p/a/i[starts-with(@id, 'toggle_table_buttondivChart_')]")); if (!elements.isEmpty()) { moreStatisticsLink = new MoreStatisticsLink(chartElement); } elements = chartElement.findElements(By.xpath("./table[starts-with(@class, 'globalTest')]")); if (!elements.isEmpty()) { this.globalTestTable = new GraphGlobalTestTable(graphUrl, elements.get(0)); } elements = driver.findElements(By.xpath("//div[@class='alert']")); if (!elements.isEmpty()) { if (elements.get(0).getText().contains("Statistics Failed")) { statisticsFailed = true; } } } catch (NoSuchElementException | TimeoutException te) { System.out.println("Expected graph page url but found none. Graph URL:\n\t" + graphUrl); throw te; } catch (Exception e) { String message = "EXCEPTION processing page: " + e.getLocalizedMessage() + ". Graph URL:\n\t" + graphUrl; System.out.println(message); throw new TestException(message, e); } }