List of usage examples for org.openqa.selenium By className
public static By className(String className)
From source file:com.nosoftskills.travianbot.page.AlliancePlayers.java
License:Apache License
public List<String> getPlayers() { List<WebElement> playerElements = webDriver.findElements(By.className("player")); return playerElements.stream().map(this::getPlayerName).collect(Collectors.toList()); }
From source file:com.nosoftskills.travianbot.page.FarmList.java
License:Apache License
public void raidSingleList(String listName) { List<WebElement> listTitles = webDriver.findElements(By.className("listTitleText")); int i = 0;//from w ww. j a v a 2 s . com for (WebElement listTitle : listTitles) { if (listTitle.getText().trim().equals(listName)) { break; } i++; } List<WebElement> raidTables = webDriver.findElements(By.className("list")); if (raidTables.size() == 0) { throw new IllegalStateException( "Page was not loaded. Most probably the server is down or you don't have internet"); } List<WebElement> startRaidButtons = webDriver.findElements(By.tagName("button")).stream().filter( buttonElement -> buttonElement.getAttribute("value").equals(" ")) .collect(Collectors.toList()); doRaid(raidTables.get(i), startRaidButtons.get(i)); }
From source file:com.nosoftskills.travianbot.page.FarmList.java
License:Apache License
private static void selectGreen(WebElement webElement) { webElement.findElements(By.className("slotRow")).stream().filter(FarmList::isGreenFlag) .forEach(FarmList::select);/*from ww w .j av a 2s . c o m*/ }
From source file:com.nosoftskills.travianbot.page.FarmList.java
License:Apache License
private static boolean isGreenFlag(WebElement webElement) { try {/* w w w . java 2 s. c o m*/ webElement.findElement(By.className("iReport1")); return true; } catch (NoSuchElementException ex) { return false; } }
From source file:com.nosoftskills.travianbot.page.FarmList.java
License:Apache License
private static void select(WebElement webElement) { webElement.findElement(By.className("markSlot")).click(); }
From source file:com.nosoftskills.travianbot.page.Home.java
License:Apache License
private IncomingAttack createIncomingAttack(WebElement webElement) { IncomingAttack incomingAttack = new IncomingAttack(webElement.findElement(By.className("name")).getText()); incomingAttack.setVillageLink(webElement.findElement(By.tagName("a")).getAttribute("href")); return incomingAttack; }
From source file:com.nosoftskills.travianbot.page.Home.java
License:Apache License
private IncomingAttack attachAttackDetails(IncomingAttack incomingAttack) { webDriver.get(incomingAttack.getVillageLink()); WebElement movementsTable = webDriver.findElement(By.id("movements")); WebElement attackRow = movementsTable.findElements(By.tagName("tr")).stream() .filter(webElement -> !webElement.findElements(By.cssSelector(".att1")).isEmpty() || !webElement.findElements(By.cssSelector(".att3")).isEmpty()) .findFirst().orElseThrow(IllegalArgumentException::new); incomingAttack.setInTime(attackRow.findElement(By.className("timer")).getText()); WebElement attackDescription = attackRow.findElement(By.cssSelector(".a1")); if (attackDescription == null) { attackDescription = attackRow.findElement(By.cssSelector(".a1")); }/*from w w w . j a v a2 s . c om*/ incomingAttack.setNumberOfAttacks(attackDescription.getText().split(" ")[0]); return incomingAttack; }
From source file:com.novartis.opensource.yada.test.YADAAdminTest.java
License:Apache License
/** * Asserts that menu bar has either 3 disabled buttons, when app has 0 queries, or 0 disabled buttons when * it has at least 1 query//from w ww. ja v a 2 s.com * @throws InterruptedException if any thread has interrupted the current thread */ private void validateMenues() throws InterruptedException { WebDriver d = getDriver(); // new WebDriverWait(d,20).until(ExpectedConditions.presenceOfElementLocated(By.id("app-qname-"+this.app))); List<WebElement> emptyWarning = d.findElements(By.className("dataTables_empty")); Thread.sleep(3000); String xpath = "//nav[contains(@class,\"main-menu\")]//li[contains(@class,\"disabled\")]/a[not(@href)]"; List<WebElement> menuButtons = d.findElements(By.xpath(xpath)); Thread.sleep(3000); //sometimes the next step takes time to appear, but WebDriverWait will throw an exception in the default case if (emptyWarning.size() > 0) Assert.assertEquals(menuButtons.size(), 3); else Assert.assertEquals(menuButtons.size(), 0); }
From source file:com.novartis.opensource.yada.test.YADAAdminTest.java
License:Apache License
/** * <ol>//w w w . j a va 2 s .co m * <li>Opens the query editor</li> * <li>Validates all the buttons are present</li> * <li>Opens the security panel</li> * <li>Sets URL validation policy</li> * <li>Sets TokenValidation policy</li> * <li>Sets ExecutionPolicy</li> * <li>Sets ContentPolicy</li> * </ol> * @throws InterruptedException if any thread has interrupted the current thread * @throws IOException when the test URL can't be accessed */ @Test(dependsOnMethods = { "testNewQueryForNewAppSave" }) public void testSecurityConfigForQuery() throws InterruptedException, IOException { WebDriver d = getDriver(); String protector = this.app + " Test Protector"; this.createQueryForNewApp(" Test Protector", "SELECT 1 AS COL1", "save"); WebElement save = d.findElement(By.id("button-save")); // validate ui WebElement e = new WebDriverWait(d, 20) .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".alert-success"))); String expected = "Hooray! Query " + protector + " was saved successfully."; Assert.assertEquals(e.getText(), expected); Assert.assertFalse(save.isDisplayed()); // close dialog d.findElement(By.id("button-cancel")).click(); Thread.sleep(3000); // restore app-mgr d.findElement(By.id("app")).click(); new WebDriverWait(d, 20).until(ExpectedConditions.presenceOfElementLocated(By.id("app-mgr"))); Thread.sleep(3000); // nav to queries d.findElement(By.id("app-qname-" + this.app)).click(); Thread.sleep(3000); // open query for edit String qname = this.app + " Test Save"; d.findElement(By.xpath("//*[text()[contains(.,\"" + qname + "\")]]")).click(); this.switchToActiveElement(d, 3000); new WebDriverWait(d, 20) .until(ExpectedConditions.presenceOfElementLocated(By.id("query-editor-container"))); // validate buttons List<WebElement> list = d.findElements(By.cssSelector("#query-editor-container .modal-footer button")); Assert.assertEquals(list.size(), 5); for (WebElement b : list) { Assert.assertTrue(b.isDisplayed() && b.isEnabled()); } // open security panel d.findElement(By.id("headingTwo")).click(); Thread.sleep(3000); // Confirm query result String result = getUrl(qname); l.debug("EXPECT NORMAL RESULT:\n" + result); Assert.assertTrue(result.contains(qname) && result.toUpperCase().contains("\"ROWS\":[{\"COL1\":\"1\"}]")); // "Mark this query as secure" and confirm "unauth" d.findElement(By.id("secure-query-ckbx")).click(); d.findElement(By.id("button-save")).click(); Thread.sleep(3000); result = getUrl(qname); l.debug("EXPECT UNAUTHORIZED RESULT:\n" + result); // should be rejected at this point due to checkbox + lack of plugin Assert.assertFalse(result.contains(qname) && result.toUpperCase().contains("\"ROWS\":[{\"COL1\":\"1\"}]")); Assert.assertTrue(result.contains("Server returned HTTP response code: 403")); d.findElement(By.id("button-cancel")).click(); // back to app-mgr Thread.sleep(3000); // open query for edit e = new WebDriverWait(d, 20).until(ExpectedConditions .presenceOfElementLocated(By.xpath("//*[text()[contains(.,\"" + qname + "\")]]"))); e.click(); this.switchToActiveElement(d, 3000); new WebDriverWait(d, 20) .until(ExpectedConditions.presenceOfElementLocated(By.id("query-editor-container"))); if (!d.findElement(By.id("secure-query-ckbx")).isDisplayed()) { d.findElement(By.id("headingTwo")).click(); Thread.sleep(3000); } // confirm "Mark this query as not secure" d.findElement(By.id("secure-query-ckbx")).click(); d.findElement(By.id("button-save")).click(); Thread.sleep(3000); result = getUrl(qname); l.debug("EXPECT NORMAL RESULT:\n" + result); // should be accepted, as box is unchecked Assert.assertTrue(result.contains(qname) && result.toUpperCase().contains("\"ROWS\":[{\"COL1\":\"1\"}]")); d.findElement(By.id("button-cancel")).click(); Thread.sleep(3000); // open query for edit e = new WebDriverWait(d, 20).until(ExpectedConditions .presenceOfElementLocated(By.xpath("//*[text()[contains(.,\"" + qname + "\")]]"))); e.click(); this.switchToActiveElement(d, 3000); new WebDriverWait(d, 20) .until(ExpectedConditions.presenceOfElementLocated(By.id("query-editor-container"))); if (!d.findElement(By.id("secure-query-ckbx")).isDisplayed()) { d.findElement(By.id("headingTwo")).click(); } // l.debug("Sleeping for 2 minutes to enable manual investigation"); Thread.sleep(3000); // validate all components // what is there before any data entry? WebElement plugin = d.findElement(By.className("policy-plugin")); WebElement policyArg = d.findElement(By.className("policy-arg")); WebElement argString = d.findElement(By.className("arg-string")); Assert.assertTrue(d.findElement(By.className("policy-group")).isDisplayed()); Assert.assertTrue(plugin.isDisplayed()); Assert.assertTrue(d.findElement(By.className("policy-action")).isDisplayed()); Assert.assertTrue(argString.isDisplayed()); Assert.assertTrue(d.findElement(By.className("policy-type")).isDisplayed()); Assert.assertTrue(policyArg.isDisplayed()); Assert.assertTrue(d.findElement(By.className("remove-policy")).isDisplayed()); // enter policies // what is there after each policy entry plugin.sendKeys("Gatekeeper"); Select policyType = new Select(d.findElement(By.className("policy-type"))); policyType.selectByVisibleText("URL Pattern Matching"); policyArg.clear(); policyArg.sendKeys("auth.path.rx=^(https?://)?localhost:8080/.+$"); Assert.assertEquals(argString.getText(), "auth.path.rx=^(https?://)?localhost:8080/.+$"); Select policyAction = new Select(d.findElement(By.className("policy-action"))); policyAction.selectByValue("save"); Thread.sleep(2000); policyAction.selectByValue("add-same"); //Thread.sleep(3000); String xpath = "//div[contains(@class,\"security-options\")][2]"; e = new WebDriverWait(d, 20).until(ExpectedConditions.presenceOfElementLocated(By.xpath(xpath))); List<WebElement> policies = d.findElements(By.className("security-options")); List<WebElement> policyTypes = d.findElements(By.className("policy-type")); List<WebElement> policyArgs = d.findElements(By.className("policy-arg")); policyType = new Select(policyTypes.get(1)); policyType.selectByVisibleText("Execution Policy (Indices)"); policyArgs.get(1).clear(); policyArgs.get(1).sendKeys("execution.policy.indices=0:getToken()"); Assert.assertTrue(d.findElement(By.className("policy-protector")).isDisplayed()); d.findElement(By.className("policy-protector")).sendKeys(protector); policyAction.selectByValue("save"); Thread.sleep(3000); policyAction.selectByValue("add-same"); //Thread.sleep(3000); xpath = "//div[contains(@class,\"security-options\")][3]"; e = new WebDriverWait(d, 20).until(ExpectedConditions.presenceOfElementLocated(By.xpath(xpath))); policies = d.findElements(By.className("security-options")); policyTypes = d.findElements(By.className("policy-type")); policyArgs = d.findElements(By.className("policy-arg")); List<WebElement> policyProtectors = d.findElements(By.className("policy-protector")); policyType = new Select(policyTypes.get(2)); policyType.selectByVisibleText("Execution Policy (Columns)"); policyArgs.get(2).clear(); policyArgs.get(2).sendKeys("execution.policy.columns=0:getToken()"); Assert.assertEquals(policyProtectors.size(), 2); policyProtectors.get(1).sendKeys(protector); policyAction.selectByValue("save"); Thread.sleep(2000); policyAction.selectByValue("add-same"); xpath = "(//input[contains(@class,\"security-options\")])[3]"; e = new WebDriverWait(d, 20).until(ExpectedConditions.presenceOfElementLocated(By.xpath(xpath))); policies = d.findElements(By.className("security-options")); policyTypes = d.findElements(By.className("policy-type")); policyArgs = d.findElements(By.className("policy-arg")); policyProtectors = d.findElements(By.className("policy-protector")); policyType = new Select(policyTypes.get(3)); policyType.selectByVisibleText("Content Policy"); policyArgs.get(3).clear(); policyArgs.get(3).sendKeys("content.policy.predicate=x=y"); expected = "auth.path.rx=^(https?://)?localhost:8080.+$,execution.policy.indices=0:getToken(),execution.policy.columns=token:getToken(),content.policy.predicate=x=y"; Assert.assertEquals(argString.getText(), expected); // save // multiple ways to save? (not yet) policyAction.selectByValue("save"); // TODO validate data is in db // TODO validate security works? or is this just for a standard integration test? // TODO alert user when security setting is invalid or unsavable for any reason // TODO alert user to save security settings (this may enable safety net after all) // TODO parse security param into UI when appropriate (it currently doesn't) d.findElement(By.id("button-save")).click(); Thread.sleep(3000); d.findElement(By.id("app")).click(); new WebDriverWait(d, 20).until(ExpectedConditions.presenceOfElementLocated(By.id("app-mgr"))); Thread.sleep(3000); // nav to queries d.findElement(By.id("app-qname-" + this.app)).click(); Thread.sleep(3000); // open query for edit d.findElement(By.xpath("//*[text()[contains(.,\"" + qname + "\")]]")).click(); this.switchToActiveElement(d, 3000); new WebDriverWait(d, 20) .until(ExpectedConditions.presenceOfElementLocated(By.id("query-editor-container"))); d.findElement(By.id("headingThree")).click(); Thread.sleep(3000); String actual = d.findElement(By.cssSelector("$('#default-params tbody tr:eq(0) td input:eq(1)')")) .getAttribute("value"); Assert.assertEquals(actual, expected); }