Step 1 >> Open Eclipse then click on “File”>>New>>Java Project
Give the name of project and Click on next.
Below screen will be there then click on libraries.
Below screen will be there then click on “Add library”.
Select TestNG and Click on “Next”.
Then further click on “Finish Tab”. Finally library is added and now click on “Finish Tab”.
Go to project folder and expand it then we see it is added under project folder.
Now move to create test script process. Taking a simple script. Now Right click on project >> new>>click on package
Give name of package and click finish
Right click on package>>new>>click on other
Select TestNG class and click on next
Give name for class and click on finish
Now see a class is created there where we can write test script with TestNG
Now we can write some configuration syntax code like below or these may be added further,
-: Write sytem properties like below and give driver exe path
System.setProperty(“webdriver.chrome.driver”,”D:\\path\\chromedriver.exe”);
-: Call WebDriver like below syntax
WebDriver driver =new ChromeDriver();
:- Now use get command to fetch url
driver.get(“http://qatestingtips.com”);
Note:- Complete code will be like below with required domain if don’t add then an error appears with syntax but also can be added further.
System.setProperty(“webdriver.chrome.driver”,”D:\\path\\chromedriver.exe”);
WebDriver driver =new ChromeDriver();
driver.get(“http://qatestingtips.com”);
Now add supporting jar files.
Right click on package >> Build Path>> click on Configure Build Path
Click on libraries
Click on “Add External Jars”.
Select selenium java libraries and click open
Then select from its libs folder also by using same process then click on open>>apply>>ok.
Some import statements may be missing there like below. If getting then see how to fix them.
Now hover on WebDriver and add statement
Now again hover on particular driver keyword (Right now there is ChromeDriver) and Select statement.
Then see error free script is created there like below screen.
:- Finally a script can be implemented as per need. We used previously shared search related script and run it. For now use above code example with command to find element and send values with “sendKeys” command.
:- Now we took a script for searching a related by giving input.
driver.findElement(By.xpath(“.//*[@id=’username’]”)).sendKeys(“Testng”); // give element location
Note:- Complete code will be like below
package testpackage;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
public class TestngClass {
@Test
public void f() {
System.setProperty(“webdriver.chrome.driver”, “D:\\chromedriver.exe”);
WebDriver driver =new ChromeDriver();
driver.get(“http://qatestingtips.com”);
driver.findElement(By.className(“search-input”)).sendKeys(“Testng”); // we find element with “By” keyword so import this as we have used.
}
}