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