List of usage examples for org.openqa.selenium WebDriver manage
Options manage();
From source file:testHelper.WebDriverHelper.java
public static WebDriver getDriver() { WebDriver driver = new ChromeDriver(); driver.manage().timeouts().implicitlyWait(TestConstants.IMPLICIT__WAIT_SECONDS, TimeUnit.SECONDS); return driver; }
From source file:testingGR.WaitTool.java
License:Open Source License
/** * Wait for the element to be present in the DOM, and displayed on the page. * And returns the first WebElement using the given method. * /*from ww w . ja v a2 s.c o m*/ * @param WebDriver * The driver object to be used * @param By * selector to find the element * @param int The time in seconds to wait until returning a failure * * @return WebElement the first WebElement using the given method, or null * (if the timeout is reached) */ public static WebElement waitForElement(WebDriver driver, final By by, int timeOutInSeconds) { WebElement element; try { // To use WebDriverWait(), we would have to nullify // implicitlyWait(). // Because implicitlyWait time also set "driver.findElement()" wait // time. // info from: // https://groups.google.com/forum/?fromgroups=#!topic/selenium-users/6VO_7IXylgY driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); // nullify // implicitlyWait() WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds); element = wait.until(ExpectedConditions.visibilityOfElementLocated(by)); driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); // reset // implicitlyWait return element; // return the element } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:testingGR.WaitTool.java
License:Open Source License
/** * Wait for the List<WebElement> to be present in the DOM, regardless of * being displayed or not. Returns all elements within the current page DOM. * // w w w . j a v a 2 s. c om * @param WebDriver * The driver object to be used * @param By * selector to find the element * @param int The time in seconds to wait until returning a failure * * @return List<WebElement> all elements within the current page DOM, or * null (if the timeout is reached) */ public static List<WebElement> waitForListElementsPresent(WebDriver driver, final By by, int timeOutInSeconds) { List<WebElement> elements; try { driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); // nullify // implicitlyWait() WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds); wait.until((new ExpectedCondition<Boolean>() { @Override public Boolean apply(WebDriver driverObject) { return areElementsPresent(driverObject, by); } })); elements = driver.findElements(by); driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); // reset // implicitlyWait return elements; // return the element } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:testingGR.WaitTool.java
License:Open Source License
/** * Wait for an element to appear on the refreshed web-page. And returns the * first WebElement using the given method. * * This method is to deal with dynamic pages. * //from ww w. j a va 2 s . co m * Some sites I (Mark) have tested have required a page refresh to add * additional elements to the DOM. Generally you (Chon) wouldn't need to do * this in a typical AJAX scenario. * * @param WebDriver * The driver object to use to perform this element search * @param locator * selector to find the element * @param int The time in seconds to wait until returning a failure * * @return WebElement the first WebElement using the given method, or * null(if the timeout is reached) * * @author Mark Collin */ public static WebElement waitForElementRefresh(WebDriver driver, final By by, int timeOutInSeconds) { WebElement element; try { driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); // nullify // implicitlyWait() new WebDriverWait(driver, timeOutInSeconds) { }.until(new ExpectedCondition<Boolean>() { @Override public Boolean apply(WebDriver driverObject) { driverObject.navigate().refresh(); // refresh the page // **************** return isElementPresentAndDisplay(driverObject, by); } }); element = driver.findElement(by); driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); // reset // implicitlyWait return element; // return the element } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:testingGR.WaitTool.java
License:Open Source License
/** * Wait for the Text to be present in the given element, regardless of being * displayed or not.//from w w w . j a va 2s . c om * * @param WebDriver * The driver object to be used to wait and find the element * @param locator * selector of the given element, which should contain the text * @param String * The text we are looking * @param int The time in seconds to wait until returning a failure * * @return boolean */ public static boolean waitForTextPresent(WebDriver driver, final By by, final String text, int timeOutInSeconds) { boolean isPresent = false; try { driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); // nullify // implicitlyWait() new WebDriverWait(driver, timeOutInSeconds) { }.until(new ExpectedCondition<Boolean>() { @Override public Boolean apply(WebDriver driverObject) { return isTextPresent(driverObject, by, text); // is the Text // in the // DOM } }); isPresent = isTextPresent(driver, by, text); driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); // reset // implicitlyWait return isPresent; } catch (Exception e) { e.printStackTrace(); } return false; }
From source file:testingGR.WaitTool.java
License:Open Source License
/** * Waits for the Condition of JavaScript. * * * @param WebDriver/*from w ww. ja v a 2s . com*/ * The driver object to be used to wait and find the element * @param String * The javaScript condition we are waiting. e.g. * "return (xmlhttp.readyState >= 2 && xmlhttp.status == 200)" * @param int The time in seconds to wait until returning a failure * * @return boolean true or false(condition fail, or if the timeout is * reached) **/ public static boolean waitForJavaScriptCondition(WebDriver driver, final String javaScript, int timeOutInSeconds) { boolean jscondition = false; try { driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); // nullify // implicitlyWait() new WebDriverWait(driver, timeOutInSeconds) { }.until(new ExpectedCondition<Boolean>() { @Override public Boolean apply(WebDriver driverObject) { return (Boolean) ((JavascriptExecutor) driverObject).executeScript(javaScript); } }); jscondition = (Boolean) ((JavascriptExecutor) driver).executeScript(javaScript); driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); // reset // implicitlyWait return jscondition; } catch (Exception e) { e.printStackTrace(); } return false; }
From source file:testingGR.WaitTool.java
License:Open Source License
/** * Waits for the completion of Ajax jQuery processing by checking * "return jQuery.active == 0" condition. * * @param WebDriver// w ww . j a va 2s. c om * - The driver object to be used to wait and find the element * @param int - The time in seconds to wait until returning a failure * * @return boolean true or false(condition fail, or if the timeout is * reached) * */ public static boolean waitForJQueryProcessing(WebDriver driver, int timeOutInSeconds) { boolean jQcondition = false; try { driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); // nullify // implicitlyWait() new WebDriverWait(driver, timeOutInSeconds) { }.until(new ExpectedCondition<Boolean>() { @Override public Boolean apply(WebDriver driverObject) { return (Boolean) ((JavascriptExecutor) driverObject).executeScript("return jQuery.active == 0"); } }); jQcondition = (Boolean) ((JavascriptExecutor) driver).executeScript("return jQuery.active == 0"); driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); // reset // implicitlyWait return jQcondition; } catch (Exception e) { e.printStackTrace(); } return jQcondition; }
From source file:testrunner.orchestrator.TestOrchestrator.java
License:Apache License
public static void main(String[] args) throws Exception { String xmlPath = (args != null && args.length > 0 ? args[0] : null); if (xmlPath == null || xmlPath.trim().equals("")) { xmlPath = "/Users/daponn/personals/2014/selenium-Priya/testXML/TestHomePageAndSearch.xml"; }//from ww w.j ava 2 s . c o m if (xmlPath == null || xmlPath.trim().equals("")) { System.out.println("No XML File is passed. Please pass an XML File to run the test"); System.exit(0); } Test test = TestBuilder.buildTest(xmlPath); TestConfig testConfig = test.getTestConfig(); System.out.println("The Test Object is :" + test); if (test == null || test.getFlows() == null || test.getFlows().isEmpty()) { System.out.println("The XML :" + xmlPath + " Seems to have no Flows defined. Please specify a Valid Test with Flows"); System.exit(0); } int users = test.getUsers(); if (users <= 0) { users = 1; } ExecutorService fixedPoolExecutor = Executors.newFixedThreadPool(users); WebDriver ffDriver = null; WebDriver chromeDriver = null; WebDriver ieDriver = null; System.out.println("The testConfig is " + testConfig); List<Future<TestResult>> testResults = new ArrayList<Future<TestResult>>(); for (int user = 1; user <= users; user++) { if (testConfig.isEnableFireFox()) { FirefoxProfile seleniumProfile = null; ProfilesIni allProfile = new ProfilesIni(); seleniumProfile = allProfile.getProfile("default"); ffDriver = new FirefoxDriver(seleniumProfile); TestExecutor testExecutor = new TestExecutor(ffDriver, "FFTestUser:" + user); if (test.isResetCookies()) { ffDriver.manage().deleteAllCookies(); } testExecutor.setCurrentTestToExecute(test); Future<TestResult> result = fixedPoolExecutor.submit(testExecutor); testResults.add(result); } if (testConfig.isEnableChrome()) { System.out.println("The Chrome path is " + testConfig.getChromePath()); if (testConfig.getChromePath() != null) { System.setProperty("webdriver.chrome.driver", testConfig.getChromePath().trim()); } else { System.setProperty("webdriver.chrome.driver", "c:\\Work\\Tools\\Selenium\\chromedriver.exe"); } chromeDriver = new ChromeDriver(); TestExecutor testExecutor = new TestExecutor(chromeDriver, "ChromeTestUser:" + user); if (test.isResetCookies()) { chromeDriver.manage().deleteAllCookies(); } testExecutor.setCurrentTestToExecute(test); Future<TestResult> result = fixedPoolExecutor.submit(testExecutor); testResults.add(result); } if (testConfig.isEnableIE()) { System.setProperty("webdriver.ie.driver", testConfig.getIePath()); DesiredCapabilities caps = DesiredCapabilities.internetExplorer(); caps.setCapability(InternetExplorerDriver.ENABLE_PERSISTENT_HOVERING, false); caps.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL, "about:blank"); // caps.setCapability(InternetExplorerDriver.REQUIRE_WINDOW_FOCUS, // true); ieDriver = new InternetExplorerDriver(caps); TestExecutor testExecutor = new TestExecutor(ieDriver, "IETestUser:" + user); if (test.isResetCookies()) { ieDriver.manage().deleteAllCookies(); } testExecutor.setCurrentTestToExecute(test); Future<TestResult> result = fixedPoolExecutor.submit(testExecutor); testResults.add(result); } } for (Future<TestResult> result : testResults) { TestResult testResult = result.get(); System.out.println("Test Result is " + testResult); } fixedPoolExecutor.shutdown(); System.out.println("The test is completed "); }
From source file:testselenium.TestSel.java
public static void regNewAccount() throws InterruptedException { // ? System.setProperty("webdriver.gecko.driver", "C:\\selenium\\geckodriver.exe"); /*//from w ww . j a va 2s .c o m ProfilesIni profiles = new ProfilesIni(); FirefoxProfile profile = profiles.getProfile("WDS"); profile.setPreference("permissions.default.image", 1); // 2 - , 1 - /*profile.setPreference("network.proxy.type", 1); profile.setPreference("network.proxy.type", "121.122.123.2"); profile.setPreference("network.proxy.type", 8502); */ WebDriver webdr = new FirefoxDriver(); // profile ? default webdr.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS); //? ? webdr.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS); //? ? webdr.get("https://www.amazon.com/"); WebElement newAccountElement = webdr.findElement(By.id("nav-flyout-ya-newCust")); WebElement newAccLinkElement = newAccountElement.findElement(By.tagName("a")); // String newAccLink = newAccLinkElement.getAttribute("href"); // ? 44-47 ? ?, ? ?!!! // System.out.println(newAccLink); // ? webdr.get(newAccLink); // ? ? WebElement inputNameField = webdr.findElement(By.id("ap_customer_name")); inputNameField.sendKeys("Ignatenko Alexandr Borodach"); WebElement inputEmailField = webdr.findElement(By.id("ap_email")); inputEmailField.sendKeys("abkj67rfra@gmail.com"); WebElement inputPassField = webdr.findElement(By.id("ap_password")); inputPassField.sendKeys("1234567890"); WebElement inputPassCheckField = webdr.findElement(By.id("ap_password_check")); inputPassCheckField.sendKeys("1234567890"); WebElement regBtn = webdr.findElement(By.id("continue")); regBtn.click(); // ?? "" Thread.sleep(1000 * 7); // ? 20 ? ? ? // ? ? ? ?? click String logginedPageLink = webdr.getCurrentUrl(); webdr.get(logginedPageLink); Thread.sleep(1000 * 60); // ? 20 ? ? ? webdr.quit(); }
From source file:testselenium.TestSel.java
public static String getProveOfLogin(String email, String password) throws InterruptedException { // 86 - 96 ? ? String logginedPage = ""; System.setProperty("webdriver.gecko.driver", "C:\\selenium\\geckodriver.exe"); // ? WebDriver driver = new FirefoxDriver(); // profile ? default driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS); //? ? driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS); //? ? driver.get("https://www.amazon.com/"); WebElement authLinkBtn = driver.findElement(By.id("nav-flyout-ya-signin")); WebElement authLinkElement = authLinkBtn.findElement(By.tagName("a")); String loginLink = authLinkElement.getAttribute("href"); driver.get(loginLink); // ? , WebElement inputEmailField = driver.findElement(By.id("ap_email")); inputEmailField.sendKeys(email);/* w w w . j av a 2s .co m*/ WebElement inputPassField = driver.findElement(By.id("ap_password")); inputPassField.sendKeys(password); WebElement authBtn = driver.findElement(By.id("signInSubmit")); authBtn.click(); // ?? "" Thread.sleep(1000 * 5); // ? 20 ? ? ? // ? ? ? ?? click String logginedPageLink = driver.getCurrentUrl(); driver.get(logginedPageLink); Thread.sleep(1000 * 10); // ? 20 ? logginedPage = driver.getPageSource(); // logginedPage ? . ? ? ? ?? ? ( Hello? name! return logginedPage; }