Articles → SELENIUM → Assertions in Selenium

Assertions in Selenium






Purpose





Syntax


Assert.assertEquals(actual, expected);	


  1. Actual (string) – Actual value of the test.
  2. Expected (string) – Expected output of the test.



Scenario


  1. Convert our application to TestNG application
  2. Write a code for assertion
  3. Run the application as TestNG application

Convert our application to TestNG application




Picture showing the Convert to TestNG option in eclipse

Click to Enlarge


Write a code for assertion




package com.FirstSeleniumProject;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.Assert;
import org.testng.annotations.Test;

public class MyClass {
    @Test
    public void TestAnnotation() {
        WebDriver driver;
        String service = "IEDriverServer path";
        System.setProperty("webdriver.ie.driver", service);
        driver = new InternetExplorerDriver();
        driver.get("http://gyansangrah.com/");

        Assert.assertEquals(driver.getTitle(), "Gyan Sangrah");
    }
}



Run the application as TestNG application




Picture showing how to run the application as TestNG application

Click to Enlarge



Picture showing the result of assertion in selenium

Click to Enlarge




Posted By  -  Karan Gupta
 
Posted On  -  Tuesday, April 18, 2017

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250