WebDriverRunnerClass usage in Selenide

Tutorial 7​​ ​​ WebDriverRunner class​​ in​​ Selenide

What you will Learn:

  • Get current url

  • Invoke ‘Selenium​​ methods using getWebDriver()

  • Validate current browser type

  • current frame url

  • Code snippet

Get current url

Let us say we want to get the url of current page. We can simply do that by invoking the ‘url’ method inside ‘WebDriverRunner’ class.

We can also assert the url (see line#22)​​ 

Save and execute.​​ 

The url gets printed in console

 

 

Invoke​​ ‘Selenium’​​ methods using getWebDriver()

We can use​​ getWebDriver()​​ method to invoke ‘Selenium’ methods

As an example, let us print the page title using Selenium’s getTitle() method

 

Similarly we can use other selenium methods.

Validate current browser type

In selenide, the default browser is chrome. So during runtime, we can check the browser type. Let us use ‘isFirefox()’ method that returns a boolean

Notice​​ that, as expected,​​ ‘false’ is returned

Current frame url

We can print the current frame url

 

 

Code snippet

package​​ w2a.selenide;

 

import​​ org.openqa.selenium.By;

import​​ org.testng.Assert;

import​​ org.testng.annotations.Test;

import​​ com.codeborne.selenide.CollectionCondition;

import​​ com.codeborne.selenide.Condition;

import​​ com.codeborne.selenide.Configuration;

import​​ com.codeborne.selenide.WebDriverRunner;

import​​ static​​ com.codeborne.selenide.Selenide.*;

import​​ static​​ com.codeborne.selenide.Condition.*;

 

public​​ class​​ FirstSelenideTest {

@Test

public​​ void​​ searchTest()​​ throws​​ InterruptedException {

//open("https://www.way2automation.com/lifetime-membership-club/");

open("https://www.selenium-tutorial.com/p/selenium-online-training");

 System.out.println(WebDriverRunner.url());

//Assert.assertTrue(WebDriverRunner.url().contains("lifetime-membership-club"));

 System.out.println(WebDriverRunner.getWebDriver().getTitle());

 System.out.println(WebDriverRunner.isChrome());

 System.out.println(WebDriverRunner.currentFrameUrl());

 Thread.sleep(5000);

 }

}


Thank you for reading!

Share On

Share on facebook
Share on twitter
Share on linkedin
Share on whatsapp
Share on tumblr
Share on email

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top

Lifetime Membership Club

LIFETIME MEMBERSHIP BIG SALE - ALL LIVE COURES JUST - 7000 RS/ 99 USD
Attend All Live courses in just 7000 rs / $99 - offer ends 1st Nov 2024