Search code examples
seleniumselenium-webdriverwebdrivertestngassert

Comparing entire url through Assert.assertEquals


I want to compare the url and print, so I have used the below code. But it was comparing the whole url like as below

Actual comparison done for the below url :

https://accounts.google.com/signin/v2/identifier?service=mail&passive=true&rm=false&continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&ss=1&scc=1&ltmpl=default&ltmplcache=

Code I have used :

String URL = driver.getCurrentUrl();
Assert.assertEquals(URL, "https://accounts.google.com" );
System.out.println(URL);

Solution needed:

I want compare only the 'https://accounts.google.com'

Please help me out to solve this issue


Solution

  • I have used below code and it working fine for me

    String URL = driver.getCurrentUrl();
        if(URL.contains("url name"))
        {
            System.out.println("Landed in correct URL" +
                    "" + URL);
    
        }else
        {
            System.out.println("Landed in wrong URL");
    
        }