First Selenide Script

Tutorial 2​​ ​​ Create and execute first​​ Selenide​​ Script

What you will Learn:

  • Execute​​ first​​ selenide​​ script

  • Difference between​​ $ and $$

  • Code snippet

Execute​​ first​​ selenide​​ script

We have already setup the selenide in our previous blog

Let us select the ‘absoluteUrl’ method

So let us try to launch google

Save and execute. Notice below that the site gets launched and our test passes​​ 

Difference between​​ $ and $$

We are aware of findElement() and findElements() methods in selenium. In selenide, we use $ method to find an element and $$ to find elements.​​ 

Just type $ and hit Ctrl+spacebar to see various methods

Inspect search field

Let’s use cssselector to identify the field

We set some value using ‘setValue’ method, save and execute. Notice that the desired value gets typed in the search field

Let us go a step further and click the search button

Execute

Let us now put an assertion. Let us assert that the first link is available in the search results page. Inspect the link

Let us add the assertion as shown below

Execute. The test is pass

Let us intentionally introduce an error in the css selector

Execute. The test fails because the element is not found

Let us now capture the text of the header

Below, after capturing the text, we are asserting the actual text with expected text

Execute. The test passes

This is how we can use $ method to find an element.

Code snippet

package​​ w2a.selenide;

 

import​​ org.openqa.selenium.By;

import​​ org.testng.Assert;

import​​ org.testng.annotations.Test;

 

import​​ com.codeborne.selenide.Condition;

 

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

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

 

public​​ class​​ FirstSelenideTest {

@Test

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

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

$(By.cssSelector(".gLFyf")).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");

 Thread.sleep(1000);

 }

}


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