Skip to content

Instantly share code, notes, and snippets.

@muditlambda
Created November 1, 2021 07:02
Show Gist options
  • Select an option

  • Save muditlambda/1b5f8a24ee2a678fca9f0a8bb132fc55 to your computer and use it in GitHub Desktop.

Select an option

Save muditlambda/1b5f8a24ee2a678fca9f0a8bb132fc55 to your computer and use it in GitHub Desktop.
package com.lambdatest;
import java.net.URL;
import java.util.ArrayList;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.Test;
import org.testng.asserts.SoftAssert;
public class SoftAssertTest
{
private static RemoteWebDriver driver;
private static String status;
@Test
public void softAssertion() throws Exception
{
String username = "user_name";
//Enter your access key
String accesskey = "access_key";
//Enter Grid URL
String gridURL = "@hub.lambdatest.com/wd/hub";
//Set Desired capabilities to run on Lambdatest platform
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("browserName", "chrome"); //Set Browser Name
capabilities.setCapability("version", "latest"); //Set browser version
capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get the any available one
capabilities.setCapability("build", "Hard Assert Test");
capabilities.setCapability("name", "Hard Assert Test");
capabilities.setCapability("visual", true);
driver = new RemoteWebDriver(new URL("https://"+username+":"+accesskey+gridURL), capabilities);
driver.get("https://www.lambdatest.com/");
// Creating the object of SoftAssert Class
SoftAssert softassert = new SoftAssert();
// Define expected title
String expectedtitle = "Most Powerful Cross Browser Testing Tool Online | LambdaTe";
// Extract Actual title
String actualtitle = driver.getTitle();
// Soft Assertion applied to validate the result
softassert.assertEquals(actualtitle, expectedtitle,"Title is not Matched");
System.out.println("This statement will be executed even the previous statement is failed");
}
@AfterTest
public void tearDown() throws Exception
{
if (driver != null)
{
driver.quit();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment