This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String downloadFilepath = "c:\\temp"; | |
HashMap<String, Object> chromePrefs = new HashMap<>(); | |
chromePrefs.put("profile.default_content_settings.popups", 0); | |
chromePrefs.put("download.default_directory", downloadFilepath); | |
chromeOptions.setExperimentalOption("prefs", chromePrefs); | |
chromeOptions.addArguments("--test-type"); | |
chromeOptions.addArguments("start-maximized", "disable-popup-blocking"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void waitForAjaxComplete() { | |
wait.until(x -> | |
{ | |
JavascriptExecutor javascriptExecutor = (JavascriptExecutor) driver; | |
Boolean isAjaxCallComplete = | |
(Boolean)javascriptExecutor.executeScript("return window.jQuery != undefined && jQuery.active == 0"); | |
return isAjaxCallComplete ; | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void setHiddenField() { | |
//<input type="hidden" name="country" value="Bulgaria"/> | |
var theHiddenElem = driver.findElement(By.name("country")); | |
JavascriptExecutor javascriptExecutor = (JavascriptExecutor) driver; | |
javascriptExecutor.executeScript("arguments[0].value='Germany';", theHiddenElem); | |
String hiddenFieldValue = theHiddenElem.getAttribute("value"); | |
Assert.assertEquals("Germany", hiddenFieldValue); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void assertButtonEnabledDisabled() { | |
driver.navigate().to("http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_button_disabled"); | |
driver.switchTo().frame("iframeResult"); | |
var button = driver.findElement(By.xpath("/html/body/button")); | |
Assert.assertFalse(button.isEnabled()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ChromeOptions chromeOptions = new ChromeOptions(); | |
chromeOptions.addExtensions(new File("local/path/to/extension.crx")); | |
driver = new ChromeDriver(chromeOptions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void focusOnControl() { | |
driver.navigate().to("http://automatetheplanet.com/"); | |
waitUntilLoaded(); | |
var ourMissionLink = driver.findElement(By.xpath("//*[@id=\"panel-6435-0-0-4\"]/div")); | |
Actions action = new Actions(driver); | |
action.moveToElement(ourMissionLink).build().perform(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void scrollFocusToControl() { | |
driver.navigate().to("http://automatetheplanet.com/"); | |
var ourMissionLink = driver.findElement(By.xpath("//*[@id=\"panel-6435-0-0-4\"]/div")); | |
String jsToBeExecuted = String.format("window.scroll(0, {0});", ourMissionLink.getLocation().getY()); | |
JavascriptExecutor javascriptExecutor = (JavascriptExecutor) driver; | |
javascriptExecutor.executeScript(jsToBeExecuted); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void scrollFocusToControl() { | |
driver.navigate().to("http://automatetheplanet.com/"); | |
var ourMissionLink = driver.findElement(By.xpath("//*[@id=\"panel-6435-0-0-4\"]/div")); | |
String jsToBeExecuted = String.format("window.scroll(0, {0});", ourMissionLink.getLocation().getY()); | |
JavascriptExecutor javascriptExecutor = (JavascriptExecutor) driver; | |
javascriptExecutor.executeScript(jsToBeExecuted); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void navigationHistory() { | |
driver.navigate().to("https://www.codeproject.com/Articles/1078541/Advanced-WebDriver-Tips-and-Tricks-Part"); | |
driver.navigate().to("http://www.codeproject.com/Articles/1017816/Speed-up-Selenium-Tests-through-RAM-Facts-and-Myth"); | |
driver.navigate().back(); | |
Assert.assertEquals("10 Advanced WebDriver Tips and Tricks - Part 1 - CodeProject", driver.getTitle()); | |
driver.navigate().refresh(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void movingBetweenTabs() { | |
driver.navigate().to("https://www.automatetheplanet.com/"); | |
var firstLink = driver.findElement(By.xpath("//*[@id='menu-item-11362']/a")); | |
var secondLink = driver.findElement(By.xpath("//*[@id='menu-item-6']/a")); | |
String selectLinkOpenninNewTab = Keys.chord(Keys.CONTROL,Keys.RETURN); | |
firstLink.sendKeys(selectLinkOpenninNewTab); | |
secondLink.sendKeys(selectLinkOpenninNewTab); | |
Set<String> windows = driver.getWindowHandles(); | |
String firstTab = (String)windows.toArray()[1]; |