Launch different browsers types using Selenide

Tutorial 4​​ ​​ Launch different browser types​​ using​​ Selenide

What you will Learn:

  • Launch firefox browser

  • Execute test in headless mode

  • set the base url

  • hold browser open

  • screenshots captured by default for failed tests

  • Code snippet

Launch firefox browser

Chromium is the default browse that gets launched in​​ selenide.​​ 

To launch firefox browser, we have to simply add a configuration

Save and execute. Notice that Mozilla firefox browser gets launched

Execute test in headless mode

To execute test in headless mode, we can make the following setting

Save and execute. Notice that firefox browser is NOT launched. The test is pass

set the base url

We can also setup the base url and then append the desired query parameter

Save and execute. Notice below that the desired page gets launched

hold browser open

As of now, we have seen that the browser closes after the test execution.​​ 

For debugging purposes, we may want to keep the browser open once the test execution is complete.​​ 

We can do that by using below configuration

Save and execute.​​ 

Notice below that the browser page does not get closed after the test execution

screenshots captured by default for failed tests

Let​​ us intentionally fail the test by entering an incorrect css selector value​​ 

Save and execute. The test will fail.

Refresh the maven project, expand the build folder > reports > tests >look for png file

Open the png. This is the failed screenshot

Notice below that we have a screenshots configuration and the default is true viz the screenshot is taken by default if the test fails

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​​ static​​ com.codeborne.selenide.Selenide.*;

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

 

public​​ class​​ FirstSelenideTest {

@Test

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

 Configuration.browser​​ =​​ "firefox";

//Configuration.holdBrowserOpen = true;

//Configuration.headless = true;

//Configuration.baseUrl = "https://www.google.com/";

//open("search?q=way2automation");

//Configuration.screenshots

open("https://www.google.com/");

$(By.cssSelector(".gL1Fyf")).setValue("way2automation");

//$(By.cssSelector(".gNO89b")).click();

/*

 $(By.cssSelector(".LC20lb.MBeuO.DKV0Md")).shouldHave(Condition.appear);

 String actual_text = $(By.cssSelector(".LC20lb.MBeuO.DKV0Md")).getText();

 Assert.assertEquals(actual_text, "Way2Automation: Get Online​​ Selenium​​ Certification Course");

int​​ w2a_count = $$(By.cssSelector(".LC20lb.MBeuO.DKV0Md")).size();

 System.out.println("The count is -->" + w2a_count);

 //Assertion

 $$(By.cssSelector(".LC20lb.MBeuO.DKV0Md")).shouldHave(CollectionCondition.size(17));

 */

 Thread.sleep(3000);

 }

}


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 31st DEC 2024