0% found this document useful (0 votes)
34 views

Selenium 1.3

The document outlines the steps to create a TestNG test case in Selenium: 1) Install TestNG in Eclipse, create a TestNG_demo folder and XML file defining test classes 2) Create a Java project in Eclipse, add TestNG and Selenium JAR files 3) Write test code using TestNG annotations, configure the XML file, and run the test case from Eclipse.

Uploaded by

Yash Singhal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Selenium 1.3

The document outlines the steps to create a TestNG test case in Selenium: 1) Install TestNG in Eclipse, create a TestNG_demo folder and XML file defining test classes 2) Create a Java project in Eclipse, add TestNG and Selenium JAR files 3) Write test code using TestNG annotations, configure the XML file, and run the test case from Eclipse.

Uploaded by

Yash Singhal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Creation of TestNG test case in Selenium steps:

• Open eclipse->help->eclipse marketplace->find (TestNG)->install. (if already installed TestNG in


eclipse ignore this step)
• Create a folder “TestNG_demo”.
• Create a xml file with the following contents, and keep in the Test_NG folder.

<?xml version="1.0" encoding="UTF-8"?>

<suite name="Demo suite 1" verbose="1" >

<test name="Demo test 1" >

<classes>

<class name="com.techbeamers.TestA"/>

<class name="com.techbeamers.TestB"/>

<class name="com.techbeamers.TestC"/>

</classes>

</test>

</suite>
• Create a new java project in eclipse(“TestNG_Demo”)
• Add the TestNG library to your java project(right click on project “TestNG_Demo”->Build Path-
>Add Libraries)
• Choose TestNG and Finish.
• Right Click on the Package ”TestNG_Demo” ->New-> others.


• Add the selenium jar file in your package->right click on the project->build path->configuration-
>libraries ->add external jar.
• Keep the chromedriver.exe in the same folder “TestNG_Demo” and provide the path.
• Provide the xml file to the project->right click on the project “testNG_Demo”->import->xml->xml
catalog->import the xml file where you have stored (TestNG_Demo folder)
• Code
package com.techbeamers.com;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

public class SeleniumWebDriverTest {

WebDriver driver = new ChromeDriver();

@Test
public void MyFirstTestNGTestCase() throws InterruptedException {
String title = driver.getTitle();
System.out.print("Current page title is : " + title);
WebElement user = driver.findElement(By.name("userName"));
user.sendKeys("test");
WebElement pwd = driver.findElement(By.name("password"));
pwd.sendKeys("test");
WebElement signin = driver.findElement(By.name("login"));
signin.click();

Thread.sleep(1000);

System.out.print("\n'SUCCESSFUL EXECUTION!!!");
}
public void invokeBrowser() {

System.setProperty("webdriver.chrome.driver","C:\\Users\\De
ll\\Desktop\\JAVACODE\\chromedriver.exe");
driver.manage().window().maximize();
driver.get("http://newtours.demoaut.com/");
}
public void cleaupProc() {
System.out.print("\nBrowser close");
driver.quit();
}

public void f() {


}
@BeforeMethod
public void beforeMethod() {
}

@AfterMethod
public void afterMethod() {
}

• Run the TestNG test case


• Right click on the project->run as->testNG test
• Find the defauttest.html file in your TestDemo folder
C:\Users\Dell\Desktop\TestNG_Demo\TestNG_Demo\test-output\Default suite
• Run on browser

You might also like