How to use urlMatches method of org.openqa.selenium.support.ui.ExpectedConditions class

Best Selenium code snippet using org.openqa.selenium.support.ui.ExpectedConditions.urlMatches

Source:URLUtils.java Github

copy

Full Screen

...7import org.openqa.selenium.support.ui.WebDriverWait;8import java.util.regex.Pattern;9import static org.openqa.selenium.support.ui.ExpectedConditions.not;10import static org.openqa.selenium.support.ui.ExpectedConditions.or;11import static org.openqa.selenium.support.ui.ExpectedConditions.urlMatches;12import static org.openqa.selenium.support.ui.ExpectedConditions.urlToBe;13/**14 * @author Vaclav Muzikar <vmuzikar@redhat.com>15 */16public final class URLUtils {17 public static void navigateToUri(WebDriver driver, String uri, boolean waitForMatch) {18 navigateToUri(driver, uri, waitForMatch, true);19 }20 private static void navigateToUri(WebDriver driver, String uri, boolean waitForMatch, boolean enableIEWorkaround) {21 Logger log = Logger.getLogger(URLUtils.class);22 log.info("starting navigation");23 // In IE, sometime the current URL is not correct; one of the indicators is that the target URL24 // equals the current URL25 if (driver instanceof InternetExplorerDriver && driver.getCurrentUrl().equals(uri)) {26 log.info("IE workaround: target URL equals current URL - refreshing the page");27 driver.navigate().refresh();28 }29 WaitUtils.waitForPageToLoad(driver);30 log.info("current URL: " + driver.getCurrentUrl());31 log.info("navigating to " + uri);32 driver.navigate().to(uri);33 if (waitForMatch) {34 // Possible login URL; this is to eliminate unnecessary wait when navigating to a secured page and being35 // redirected to the login page36 String loginUrl = "^[^\\?]+/auth/realms/[^/]+/(protocol|login-actions).+$";37 try {38 (new WebDriverWait(driver, 3)).until(or(urlMatches("^" + Pattern.quote(uri) + ".*$"), urlMatches(loginUrl)));39 } catch (TimeoutException e) {40 log.info("new current URL doesn't start with desired URL");41 }42 }43 WaitUtils.waitForPageToLoad(driver);44 log.info("new current URL: " + driver.getCurrentUrl());45 // In IE, after deleting the cookies for test realm, the first loaded page in master's admin console46 // contains invalid URL (misses #/realms/[realm] or contains state and code fragments), although the47 // address bar states the correct URL; seemingly this is another bug in IE WebDriver)48 if (enableIEWorkaround && driver instanceof InternetExplorerDriver49 && (driver.getCurrentUrl().matches("^[^#]+/#state=[^#/&]+&code=[^#/&]+$")50 || driver.getCurrentUrl().matches("^.+/auth/admin/[^/]+/console/$"))) {51 log.info("IE workaround: reloading the page after deleting the cookies...");52 navigateToUri(driver, uri, waitForMatch, false);53 }54 else {55 log.info("navigation complete");56 }57 }58 public static boolean currentUrlEqual(WebDriver driver, String url) {59 return urlCheck(driver, urlToBe(url));60 }61 public static boolean currentUrlDoesntEqual(WebDriver driver, String url) {62 return urlCheck(driver, not(urlToBe(url)));63 }64 public static boolean currentUrlStartWith(WebDriver driver, String url) {65 return urlCheck(driver, urlMatches("^" + Pattern.quote(url) + ".*$"));66 }67 public static boolean currentUrlDoesntStartWith(WebDriver driver, String url) {68 return urlCheck(driver, urlMatches("^(?!" + Pattern.quote(url) + ").+$"));69 }70 private static boolean urlCheck(WebDriver driver, ExpectedCondition condition) {71 return urlCheck(driver, condition, false);72 }73 private static boolean urlCheck(WebDriver driver, ExpectedCondition condition, boolean secondTry) {74 Logger log = Logger.getLogger(URLUtils.class);75 try {76 (new WebDriverWait(driver, 1, 100)).until(condition);77 }78 catch (TimeoutException e) {79 if (driver instanceof InternetExplorerDriver && !secondTry) {80 // IE WebDriver has sometimes invalid current URL81 log.info("IE workaround: checking URL failed at first attempt - refreshing the page and trying one more time...");82 driver.navigate().refresh();...

Full Screen

Full Screen

Source:Explicitfun.java Github

copy

Full Screen

...23 System.out.println("urlContains results" + urlContains);24 Boolean urlToBe = wait.until(ExpectedConditions.urlToBe("http://www.vpl.ca/"));25 System.out.println("urlToBe results" + urlToBe);26 String regex = "\\b(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]";27 Boolean urlMatches = wait.until(ExpectedConditions.urlMatches(regex));28 System.out.println("urlMatches results" + urlToBe);29 // ExpectedConditions.elementToBeSelected30 WebElement searchDDwn = driver.findElement(By.xpath(".//*[@id='edit-source']"));31 Select dropdown = new Select(searchDDwn);32 dropdown.selectByValue("Website");33 WebElement selected = dropdown.getFirstSelectedOption();34 boolean elementToBeSelected = wait.until(ExpectedConditions.elementToBeSelected(selected));35 System.out.println("elementToBeSelected results" + elementToBeSelected);36 // ExpectedConditions.invisibilityOfElementLocated37 By searchDDwn1 = By.xpath(".//*[@id='edit-source1']");38 boolean invisibilityOfElementLocated = wait.until(ExpectedConditions.invisibilityOfElementLocated(searchDDwn1));39 System.out.println("invisibilityOfElementLocated results" + invisibilityOfElementLocated);40 // ExpectedConditions.invisibilityOfElementWithText41 By searchDDwn2 = By.xpath(".//*[text()='edit-source1']");42 boolean invisibilityOfElementWithText = wait...

Full Screen

Full Screen

Source:Helpers.java Github

copy

Full Screen

...14 //private static WebDriver webDriver = DriverFactory.getDriver();15 public static void WaitTillUrlMatch(WebDriver webDriver,int timeInSec, String expectedUrl)16 {17 WebDriverWait wait = new WebDriverWait(webDriver, timeInSec);18 wait.until(ExpectedConditions.urlMatches(expectedUrl));19 }20 public static void WaitTillSubsidieUrlMatch(WebDriver webDriver,int timeInSec,String expectedRelativeUrl)21 {22 WebDriverWait wait = new WebDriverWait(webDriver, timeInSec);23 wait.until(ExpectedConditions.urlMatches(data.getSubsidieBaseUrl()+expectedRelativeUrl));24 }25 public static void WaitTillUrlContain(WebDriver webDriver,int timeInSec,String expectedRelativeUrl)26 {27 WebDriverWait wait = new WebDriverWait(webDriver, timeInSec);28 wait.until(ExpectedConditions.urlContains(data.getSubsidieBaseUrl()+expectedRelativeUrl));29 }30 public static void waitForLoad(WebDriver webDriver) {31 ExpectedCondition<Boolean> pageLoadCondition = driver1 -> ((JavascriptExecutor) driver1).executeScript("return document.readyState").equals("complete");32 WebDriverWait wait = new WebDriverWait(webDriver, 30);33 wait.until(pageLoadCondition);34 }35 public static void SwitchToLatestTab(WebDriver webDriver) {36 ArrayList<String> tabs = new ArrayList<>(webDriver.getWindowHandles());37 int tabsSize=tabs.size();...

Full Screen

Full Screen

Source:UserLoginPageTest.java Github

copy

Full Screen

...39 page.setUserName("007");40 page.setPassword("shakennotstirred62");41 page.submitLogin();42 WebDriverWait wait = new WebDriverWait(driver, 3);43 wait.until(ExpectedConditions.urlMatches("/welcome.html"));44 assertEquals("http://localhost:9009/html/welcome.html", driver.getCurrentUrl());45 }46 47 @Test public void testFailLogin() {48 page.setUserName("000");49 page.setPassword("secretagentman");50 page.submitLogin();51 WebDriverWait wait = new WebDriverWait(driver, 3);52 wait.until(ExpectedConditions.urlMatches("/loginretry.html"));53 assertEquals("http://localhost:9009/html/loginretry.html", driver.getCurrentUrl());54 }55 56 @Test public void testFailLoginDifferentUsersPassword() {57 page.setUserName("007");58 page.setPassword("suckitTrebek");59 page.submitLogin();60 WebDriverWait wait = new WebDriverWait(driver, 3);61 wait.until(ExpectedConditions.urlMatches("/loginretry.html"));62 assertEquals("http://localhost:9009/html/loginretry.html", driver.getCurrentUrl());63 }64 65 @Test public void testFailToBypassLogin() {66 page.navigateTo("http://localhost:9009/html/welcome.html");67 page.logout();68 page.navigateTo("http://localhost:9009/html/welcome.html");69 WebDriverWait wait = new WebDriverWait(driver, 3);70 wait.until(ExpectedConditions.urlMatches("/loginretry.html"));71 assertEquals("http://localhost:9009/html/loginretry.html", driver.getCurrentUrl());72 }73 74}...

Full Screen

Full Screen

Source:logginPageTest.java Github

copy

Full Screen

...44 page.setUsername("mendozam");45 page.setPassword("Tacos");46 page.submit();47 WebDriverWait wait = new WebDriverWait(driver,60);48 wait.until(ExpectedConditions.urlMatches("/employee.html"));49 assertEquals("http://localhost:9012/html/employee.html",driver.getCurrentUrl());50 }51 52 @Test53 public void failedLoginEmployee() {54 page.setUsername("mendozam");55 page.setPassword("tacos");56 page.submit();57 WebDriverWait wait = new WebDriverWait(driver,60);58 wait.until(ExpectedConditions.urlMatches("/notFound.html"));59 assertEquals("http://localhost:9012/html/notFound.html",driver.getCurrentUrl());60 }61 62 @Test63 public void testSuccessfulLoginManager() {64 page.setUsername("Alanmz");65 page.setPassword("1234");66 page.submit();67 WebDriverWait wait = new WebDriverWait(driver,60);68 wait.until(ExpectedConditions.urlMatches("/manager.html"));69 assertEquals("http://localhost:9012/html/manager.html",driver.getCurrentUrl());70 }71 72 @Test73 public void failedLoginManager() {74 page.setUsername("Alanmz");75 page.setPassword("134");76 page.submit();77 WebDriverWait wait = new WebDriverWait(driver,60);78 wait.until(ExpectedConditions.urlMatches("/notFound.html"));79 assertEquals("http://localhost:9012/html/notFound.html",driver.getCurrentUrl());80 }81 82}...

Full Screen

Full Screen

Source:WelcomePageTest.java Github

copy

Full Screen

...33 @Test 34 public void testNavToMyReimbursements() {35 page.goToMyReimbursements();36 WebDriverWait wait = new WebDriverWait(driver, 1);37 wait.until(ExpectedConditions.urlMatches("/reimbursements.html"));38 assertEquals("http://localhost:9009/html/reimbursements.html", driver.getCurrentUrl());39 }40 41 @Test42 public void testNavToProcessReimbursements() {43 page.goToProcessReimbursements();44 WebDriverWait wait = new WebDriverWait(driver, 1);45 wait.until(ExpectedConditions.urlMatches("/processreimbursements.html"));46 assertEquals("http://localhost:9009/html/processreimbursements.html", driver.getCurrentUrl());47 }48 49 @Test50 public void testCreateRequest() {51 page.goToRequestReimbursement();52 page.setExpenseAmount("222.22");53 page.setExpenseDescription("Automated martini bill");54 page.selectRequestReimbursementType("food");55 page.createRequestReimbursement();56 WebDriverWait wait = new WebDriverWait(driver, 1);57 wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.id("closeModal"))));58 assertTrue(driver.findElement(By.id("closeModal")).isDisplayed());59 }...

Full Screen

Full Screen

Source:reusableWaits.java Github

copy

Full Screen

...21 }22 public static String waitForSelectClubPage(int seconds) {23 WebDriverWait wait = new WebDriverWait(driver, seconds);24 wait.until(ExpectedConditions25 .urlMatches("https://ess-web-future2.test-jfisoftware.com:8945/CompeteOnTheGo/Account/ClubSelection"));26 return null;27 }28 29 public static String waitForDashboard(int seconds) {30 WebDriverWait wait = new WebDriverWait(driver, seconds);31 wait.until(ExpectedConditions32 .urlMatches("https://ess-web-future2.test-jfisoftware.com:8945/CompeteOnTheGo/"));33 return null;34 } 35}...

Full Screen

Full Screen

Source:CustomWaits.java Github

copy

Full Screen

...23 public String waitForSelectClubPage(int seconds) {24 25 WebDriverWait wait = new WebDriverWait(driver, seconds);26 wait.until(ExpectedConditions27 .urlMatches("https://ess-web-future2.test-jfisoftware.com:8945/CompeteOnTheGo/Account/ClubSelection"));28 return null;29 }30 public String waitForDashboard(int seconds) {31 32 WebDriverWait wait = new WebDriverWait(driver, seconds);33 wait.until(ExpectedConditions.urlMatches("https://ess-web-future2.test-jfisoftware.com:8945/CompeteOnTheGo/"));34 return null;35 }36}...

Full Screen

Full Screen

urlMatches

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.support.ui.ExpectedConditions;2import org.openqa.selenium.support.ui.WebDriverWait;3import org.openqa.selenium.By;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.WebElement;6import org.openqa.selenium.chrome.ChromeDriver;7import org.openqa.selenium.support.ui.ExpectedCondition;8public class urlMatches {9 public static void main(String[] args) {10 System.setProperty("webdriver.chrome.driver", "C:\\Users\\hp\\Desktop\\Selenium\\chromedriver.exe");11 WebDriver driver = new ChromeDriver();12 WebDriverWait wait = new WebDriverWait(driver, 10);13 driver.quit();14 }15}16Starting ChromeDriver 2.35.528161 (8a06b8f64c1e165a45c139b48b05e231b05d6e1a) on port 15195

Full Screen

Full Screen

urlMatches

Using AI Code Generation

copy

Full Screen

1package com.seleniumsimplified.webdriver;2import org.junit.*;3import org.openqa.selenium.*;4import org.openqa.selenium.firefox.FirefoxDriver;5import org.openqa.selenium.support.ui.ExpectedConditions;6import org.openqa.selenium.support.ui.WebDriverWait;7public class ExplicitWaitExampleTest {8 WebDriver driver;9 WebDriverWait wait;10 public void setUp(){11 driver = new FirefoxDriver();12 wait = new WebDriverWait(driver, 10);13 }14 public void exampleOfExplicitWait(){15 driver.findElement(By.cssSelector("option[value='3']")).click();16 WebElement category = driver.findElement(By.id("combo1"));17 category.findElement(By.cssSelector("option[value='23']")).click();18 driver.findElement(By.name("submitbutton")).click();19 WebElement para = driver.findElement(By.id("_valuelanguage_id"));20 Assert.assertEquals("23", para.getText().trim());21 }22 public void tearDown(){23 driver.quit();24 }25}

Full Screen

Full Screen

urlMatches

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.support.ui.ExpectedConditions2import org.openqa.selenium.support.ui.WebDriverWait3import org.openqa.selenium.WebDriver4import org.openqa.selenium.chrome.ChromeDriver5WebDriver driver = new ChromeDriver()6WebDriverWait wait = new WebDriverWait(driver, 5)7driver.close()8import org.openqa.selenium.support.ui.ExpectedConditions9import org.openqa.selenium.support.ui.WebDriverWait10import org.openqa.selenium.WebDriver11import org.openqa.selenium.chrome.ChromeDriver12WebDriver driver = new ChromeDriver()13WebDriverWait wait = new WebDriverWait(driver, 5)14driver.close()

Full Screen

Full Screen

urlMatches

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.By;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.WebElement;4import org.openqa.selenium.chrome.ChromeDriver;5import org.openqa.selenium.support.ui.ExpectedConditions;6import org.openqa.selenium.support.ui.WebDriverWait;7public class Test {8 public static void main(String[] args) throws InterruptedException {9 System.setProperty("webdriver.chrome.driver", "C:\\Users\\Admin\\Downloads\\chromedriver_win32\\chromedriver.exe");10 WebDriver driver = new ChromeDriver();11 WebDriverWait wait = new WebDriverWait(driver, 10);12 alertButton.click();13 driver.switchTo().alert().accept();14 confirmButton.click();15 driver.switchTo().alert().accept();16 promptButton.click();17 driver.switchTo().alert().sendKeys("Hello");18 driver.switchTo().alert().accept();19 promptButton.click();20 driver.switchTo().alert().sendKeys("Hello");21 driver.switchTo().alert().dismiss();22 driver.close();23 }24}

Full Screen

Full Screen

Selenium 4 Tutorial:

LambdaTest’s Selenium 4 tutorial is covering every aspects of Selenium 4 testing with examples and best practices. Here you will learn basics, such as how to upgrade from Selenium 3 to Selenium 4, to some advanced concepts, such as Relative locators and Selenium Grid 4 for Distributed testing. Also will learn new features of Selenium 4, such as capturing screenshots of specific elements, opening a new tab or window on the browser, and new protocol adoptions.

Chapters:

  1. Upgrading From Selenium 3 To Selenium 4?: In this chapter, learn in detail how to update Selenium 3 to Selenium 4 for Java binding. Also, learn how to upgrade while using different build tools such as Maven or Gradle and get comprehensive guidance for upgrading Selenium.

  2. What’s New In Selenium 4 & What’s Being Deprecated? : Get all information about new implementations in Selenium 4, such as W3S protocol adaption, Optimized Selenium Grid, and Enhanced Selenium IDE. Also, learn what is deprecated for Selenium 4, such as DesiredCapabilites and FindsBy methods, etc.

  3. Selenium 4 With Python: Selenium supports all major languages, such as Python, C#, Ruby, and JavaScript. In this chapter, learn how to install Selenium 4 for Python and the features of Python in Selenium 4, such as Relative locators, Browser manipulation, and Chrom DevTool protocol.

  4. Selenium 4 Is Now W3C Compliant: JSON Wireframe protocol is retiring from Selenium 4, and they are adopting W3C protocol to learn in detail about the advantages and impact of these changes.

  5. How To Use Selenium 4 Relative Locator? : Selenium 4 came with new features such as Relative Locators that allow constructing locators with reference and easily located constructors nearby. Get to know its different use cases with examples.

  6. Selenium Grid 4 Tutorial For Distributed Testing: Selenium Grid 4 allows you to perform tests over different browsers, OS, and device combinations. It also enables parallel execution browser testing, reads up on various features of Selenium Grid 4 and how to download it, and runs a test on Selenium Grid 4 with best practices.

  7. Selenium Video Tutorials: Binge on video tutorials on Selenium by industry experts to get step-by-step direction from automating basic to complex test scenarios with Selenium.

Selenium 101 certifications:

LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful