100% found this document useful (1 vote)
4K views2 pages

Selenium HandsOn

The document discusses various TestNG annotations and configurations for testing with TestNG. It covers helper attributes to include or exclude test classes, group tags to run specific test groups, parameters to pass data to tests, data providers to read test data from a 2D array, and reading test data from a JSON file using a JSON parser.

Uploaded by

aman kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
4K views2 pages

Selenium HandsOn

The document discusses various TestNG annotations and configurations for testing with TestNG. It covers helper attributes to include or exclude test classes, group tags to run specific test groups, parameters to pass data to tests, data providers to read test data from a 2D array, and reading test data from a JSON file using a JSON parser.

Uploaded by

aman kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

TestNG - Helper Attributes

<classes>
<class name="arithmeticOperation.Addition"/>
<class name="arithmeticOperation.Subtraction"/>
<class name="arithmeticOperation.Multiplication"/>
<class name="arithmeticOperation.Division"/>
</classes>

Addition file:
@Test (enabled=true)

Multiplication:
@Test(priority=0)

Division:
@Test
@Test(dependsOnMethods = "divMeth_1" )
@Test(dependsOnMethods = "divMeth_2" )

Subtraction:
@Test ( timeOut = 500 )
------------------------------------------------
TestNG - Group Tags

<groups>
<run>
<include name="Addition"/>
</run>
</groups>
<classes>
<class name="arithmeticOperators.Arithmetic"/>
</classes>

@Test(groups= "Addition")
Assert.assertEquals(c,c);
-------------------------------------------------
TestNG - Parameters
@Parameters({"url","keyword"})
public void googleSearch (String url, String keyword)throws InterruptedException
{
driver.get(url);

System.out.println(url);
System.out.println(keyword);

driver.manage().window().maximize();
driver.findElement(By.name("q")).sendKeys(keyword);

Thread.sleep(2000);
System.out.println("Page title is: " + driver.getTitle());

<parameter name="url" value="https://www.google.com" />


<parameter name="keyword" value="Fresco Play" />
<test name="google">
<classes>
<class name="googleSearch.GoogleSearch">
<methods>
<include name="googleSearch" />
</methods>
</class>
</classes>

This study source was downloaded by 100000817604580 from CourseHero.com on 01-26-2022 09:48:34 GMT -06:00

https://www.coursehero.com/file/76836674/Selenium-HandsOntxt/
</test>
-------------------------------------------------
TestNG - Data Provider

@Test(dataProvider="getdata")

public void googleSearch(String keyword){


driver.findElement(By.name("q")).sendKeys(keyword);
System.out.println("We have successfully Searched for " + keyword);

Object[][] data = new Object[3][1];

data[0][0]="Fresco Play";
data[1][0]="Fresco Apps";
data[2][0]="Ultimatix";

-------------------------------------------------
DDT - JSON
{
"UserName" : "TestData",
"Password" : "Test@123",
"Confirm Password" : "Test@123"
}
WebDriver driver;
String url,userName,password,conPassword;
*******************************************************
Object obj = parser.parse(new FileReader("Registration.json"));
JSONObject jsonObject = (JSONObject) obj;

Object obj = parser.parse(new FileReader("/Registration.json"));


JSONObject jsonObject = (JSONObject) obj;
-----*-*-*-*-**
JSONObject obj;
obj=loadJSONObject("Registration.json");
JSONObject jsonObject = (JSONObject) obj;

*********************************************
url = (String) jsonObject.get("URL");
userName = (String) jsonObject.get("UserName");
password = (String) jsonObject.get("Password");
conPassword = (String) jsonObject.get("Confirm Password");

driver.get(url);
driver.findElement(By.xpath("/html/body/div/table/tbody/tr/td[2]/table/tbody/tr[
2]/td/table/tbody/tr/td[2]/a")).click();
//driver.findElement(By.linkText("REGISTER")).click();
driver.findElement(By.id("email")).sendKeys(userName);
driver.findElement(By.name("password")).sendKeys(password);
driver.findElement(By.name("confirmPassword")).sendKeys(conPassword);
driver.findElement(By.name("register")).click();

53,19
56,19
63,27
63.6
67.10
68.10

This study source was downloaded by 100000817604580 from CourseHero.com on 01-26-2022 09:48:34 GMT -06:00

https://www.coursehero.com/file/76836674/Selenium-HandsOntxt/
Powered by TCPDF (www.tcpdf.org)

You might also like