List of usage examples for org.openqa.selenium WebDriver getCurrentUrl
String getCurrentUrl();
From source file:org.keycloak.testsuite.util.WaitUtils.java
License:Apache License
/** * Waits for page to finish any pending redirects, REST API requests etc. * Because Keycloak's Admin Console is a single-page application, we need to * take extra steps to ensure the page is fully loaded *///from w w w. j a v a2 s .c o m public static void waitForPageToLoad() { WebDriver driver = getCurrentDriver(); if (driver instanceof HtmlUnitDriver) { return; // not needed } String currentUrl = null; // Ensure the URL is "stable", i.e. is not changing anymore; if it'd changing, some redirects are probably still in progress for (int maxRedirects = 4; maxRedirects > 0; maxRedirects--) { currentUrl = driver.getCurrentUrl(); FluentWait<WebDriver> wait = new FluentWait<>(driver).withTimeout(Duration.ofMillis(250)); try { wait.until(not(urlToBe(currentUrl))); } catch (TimeoutException e) { break; // URL has not changed recently - ok, the URL is stable and page is current } if (maxRedirects == 1) { log.warn("URL seems unstable! (Some redirect are probably still in progress)"); } } WebDriverWait wait = new WebDriverWait(getCurrentDriver(), PAGELOAD_TIMEOUT_MILLIS / 1000); ExpectedCondition waitCondition = null; // Different wait strategies for Admin and Account Consoles if (currentUrl.matches("^[^\\/]+:\\/\\/[^\\/]+\\/auth\\/admin\\/.*$")) { // Admin Console // Checks if the document is ready and asks AngularJS, if present, whether there are any REST API requests in progress waitCondition = javaScriptThrowsNoExceptions("if (document.readyState !== 'complete' " + "|| (typeof angular !== 'undefined' && angular.element(document.body).injector().get('$http').pendingRequests.length !== 0)) {" + "throw \"Not ready\";" + "}"); } else if (currentUrl.matches("^[^\\/]+:\\/\\/[^\\/]+\\/auth\\/realms\\/[^\\/]+\\/account\\/.*$") // check for Account Console URL && driver.getPageSource().contains("patternfly-ng") // check for new Account Console (don't use this strategy with the old one) ) { waitCondition = javaScriptThrowsNoExceptions( "if (!window.getAngularTestability(document.querySelector('app-root')).isStable()) {" + "throw 'Not ready';" + "}"); } if (waitCondition != null) { try { wait.until(waitCondition); } catch (TimeoutException e) { log.warn("waitForPageToLoad time exceeded!"); } } }
From source file:org.mitre.mpf.wfm.ui.CreateJobPage.java
License:Open Source License
public CreateJobPage(WebDriver driver) { if (!ValidPage(driver)) { throw new IllegalStateException( "This is not Home Page of logged in user, current page is: " + driver.getCurrentUrl()); }//w ww . ja v a2 s .c om }
From source file:org.mitre.mpf.wfm.ui.CreateJobPage.java
License:Open Source License
public static boolean ValidPage(WebDriver driver) { log.debug("Current Title:" + driver.getTitle() + " Desired:" + PAGE_TITLE); return driver.getTitle().startsWith(PAGE_TITLE) && driver.getCurrentUrl().contains(PAGE_URL) && Utils.checkIDExists(driver, "jobPipelineSelectServer"); }
From source file:org.mitre.mpf.wfm.ui.CreateJobPage.java
License:Open Source License
public static CreateJobPage getCreateJobPage(WebDriver driver) { //must be on homepage if (!HomePage.ValidPage(driver)) { throw new IllegalStateException( "This is not Home Page of logged in user, current page" + "is: " + driver.getCurrentUrl()); }//from ww w . jav a 2s .c o m // click the nav link Utils.safeClickById(driver, CreateJobPage.NAV_ID); // Wait for the login page to load, timeout after 10 seconds (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { return CreateJobPage.ValidPage(d); } }); return new CreateJobPage(driver); }
From source file:org.mitre.mpf.wfm.ui.CreateJobPage.java
License:Open Source License
/** * Run a job on the server media//from www. j a v a 2 s . co m * @param driver * @param base_url * @return * @throws InterruptedException */ public JobStatusPage createJobFromUploadedMedia(WebDriver driver, String base_url, String filename, String pipeline_name, int priority, int num_rows) throws InterruptedException { log.info("[CreateJobPage] createJobFromUploadedMedia"); if (!CreateJobPage.ValidPage(driver)) { throw new IllegalStateException("This is not the correct page, current page" + "is: " + driver.getCurrentUrl() + " should be " + this.PAGE_URL); } //switch to uploads //Utils.safeClickById(driver, "btn-display-upload-root"); //media will not be checked //Thread.sleep(2000);//wait for it to populate //log.info("View Uploads Only tab click"); //click on the remote-media directory and wait for it log.info("clicking remote-media"); List<WebElement> rows = driver.findElements(By.className("list-group-item")); int idx = rows.size(); //log.info("#level directories:" + idx); boolean found = false; for (WebElement row : rows) { String ele = row.getText(); //log.info(ele); if (ele.equals("remote-media")) { row.click(); found = true; } } if (!found) { // Using the TestNG API for logging throw new IllegalStateException("remote-media not found " + driver.getCurrentUrl()); } // wait for files to load (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { return d.findElement(By.id("file_list_server")) != null; }//may need to check for li }); /* log.info("finding the first uploaded file"); rows = driver.findElements(By.xpath("//table[@id='file_list_server']/tbody/tr")); idx = rows.size(); if(rows.size() <= 1 && idx < num_rows){ log.error("[createJobFromUploadedMedia] No Files in the media"); throw new IllegalStateException("[createJobFromUploadedMedia] No Files in the media " + driver.getCurrentUrl()); } log.info("#Files Available:" + idx); */ log.info("finding the file: " + filename); WebElement search = driver.findElement(By.xpath("//div[@id='file_list_server_filter']/label/input")); search.sendKeys(filename);//search Thread.sleep(2000); //select the first file log.info("clicking the uploaded file:" + filename); driver.findElement(By.xpath("//table[@id='file_list_server']/tbody/tr[1]/td[1]/input")).click(); //select the desired pipeline from the select list found = safeSelectUiSelectByText(driver, "jobPipelineSelectServer", pipeline_name); log.info("Pipeline found:" + found); Thread.sleep(1000); //select the desired priority log.info("clicking the priority"); found = safeSelectUiSelectByIndex(driver, "jobPrioritySelectServer", priority); log.info("Priority found:" + found); //quick sleep to make sure the angular controller process all events Thread.sleep(1000); log.info("submit job "); Utils.safeClickById(driver, "btn-submit-checked"); //submit media log.info("Wait 10 sec for job status"); (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { return JobStatusPage.ValidPage(d); } }); log.info("on job status page"); return new JobStatusPage(driver); }
From source file:org.mitre.mpf.wfm.ui.HomePage.java
License:Open Source License
public HomePage(WebDriver driver) { if (!ValidPage(driver)) { throw new IllegalStateException("This is not Home Page of logged in user, current page is: " + driver.getCurrentUrl() + " Title:" + driver.getTitle()); }//from w w w . jav a2s .c om }
From source file:org.mitre.mpf.wfm.ui.HomePage.java
License:Open Source License
/** * Login as valid user//w w w . j a v a 2 s.c o m * * @param userName * @param password * @return HomePage object */ public LoginPage logout(WebDriver driver) { if (!ValidPage(driver)) { throw new IllegalStateException( "This is not Home Page of logged in user, current page" + "is: " + driver.getCurrentUrl()); } try { //clear all popups if possible when trying to logout //while noty popups exist while (driver.findElement(By.className("noty_text")) != null) { //click the "Close All" button Utils.safeClickById(driver, "button-1"); //sleep for a second to wait for noty to display others from the // queue since "Close All" now only closes what is visible try { Thread.sleep(1000); } catch (InterruptedException e) { log.error("Error while sleeping for 1000ms after closing noty notifications"); } } } catch (NoSuchElementException e) { //will be thrown when driver.findElement(By.className("noty_text")) can't find the element log.info("No noty notifications present during logout."); } //Hopefully it is impossible for a noty notification to pop up between these operations // click the dropdown Utils.safeClickByCss(driver, "a.dropdown-toggle"); // click the logout link Utils.safeClickByLinkText(driver, "Logout"); // Wait for the login page to load, timeout after 10 seconds (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { return d.getTitle().startsWith(LoginPage.PAGE_TITLE); } }); return new LoginPage(driver); }
From source file:org.mitre.mpf.wfm.ui.JobStatusPage.java
License:Open Source License
public JobStatusPage(WebDriver driver) { if (!ValidPage(driver)) { throw new IllegalStateException( "This is not the correct page, current page is: " + driver.getCurrentUrl()); }//w w w . j a va2 s .co m }
From source file:org.mitre.mpf.wfm.ui.JobStatusPage.java
License:Open Source License
public static boolean ValidPage(WebDriver driver) { log.debug("Current Title:" + driver.getTitle() + " Desired:" + PAGE_TITLE + " " + driver.getCurrentUrl() + " " + Utils.checkIDExists(driver, "jobTable")); return driver.getTitle().startsWith(PAGE_TITLE) && driver.getCurrentUrl().contains(PAGE_URL) && Utils.checkIDExists(driver, "jobTable"); }
From source file:org.mitre.mpf.wfm.ui.JobStatusPage.java
License:Open Source License
public static JobStatusPage getJobStatusPage(WebDriver driver) { //must be on homepage if (!HomePage.ValidPage(driver)) { throw new IllegalStateException( "This is not Home Page of logged in user, current page" + "is: " + driver.getCurrentUrl()); }//from w ww. j av a 2 s. c o m // click the nav link Utils.safeClickById(driver, JobStatusPage.NAV_ID); // Wait for the login page to load, timeout after 10 seconds (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { return JobStatusPage.ValidPage(d); } }); return new JobStatusPage(driver); }