So I am trying the code where i take a screenshot of a web page. I have used a class to generate random string value and then assign these values to the file name. However when I run the code, it executes completely but however the screenshots are never saved into the directory.
code:
import java.io.File;
import java.util.concurrent.TimeUnit;
import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class ScreenShot {
private WebDriver driver;
private String BaseUrl;
#Before
public void setUp() throws Exception {
BaseUrl = "https://www.flock.co";
System.setProperty("webdriver.chrome.driver", "C:\\Automation\\chromedriver_win32\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
}
#Test
public void test() throws Exception {
driver.get(BaseUrl);
Thread.sleep(5000);
WebElement emailField = driver.findElement(By.xpath("//div[#id='main-area']//input"));
WebElement Button = driver.findElement(By.xpath("//div[#id='main-area']//button"));
emailField.sendKeys("incomeplete");
Button.click();
}
public static String getRandomString(int length) {
StringBuilder sb = new StringBuilder();
String characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
for (int i = 0; i < length; i++) {
int index = (int) (Math.random() * characters.length());
sb.append(characters.charAt(index));
}
return sb.toString();
}
#After
public void tearDown() throws Exception {
String fileName = getRandomString(10) + ".png";
String directory = "C:\\Users\\farzan.s.DIRECTI\\Desktop\\LetsKodeIt";
File sourceFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(sourceFile, new File(directory+fileName));
driver.quit();
}
}
However I remove this random string generator and directly specify the directory path in FileUtils, it works.
Code:
import java.io.File;
import java.util.concurrent.TimeUnit;
import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class ScreenShot {
private WebDriver driver;
private String BaseUrl;
#Before
public void setUp() throws Exception {
BaseUrl = "https://www.flock.co";
System.setProperty("webdriver.chrome.driver", "C:\\Automation\\chromedriver_win32\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
}
#Test
public void test() throws Exception {
driver.get(BaseUrl);
Thread.sleep(5000);
WebElement emailField = driver.findElement(By.xpath("//div[#id='main-area']//input"));
WebElement Button = driver.findElement(By.xpath("//div[#id='main-area']//button"));
emailField.sendKeys("incomeplete");
Button.click();
}
#After
public void tearDown() throws Exception {
File sourceFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(sourceFile, new File(C:\\Users\\farzan.s.DIRECTI\\Desktop\\LetsKodeIt\jfjfnfh.png));
driver.quit();
}
}
You missed "\\" in path.
It should be
FileUtils.copyFile(sourceFile, new File(directory+"\\"+fileName));
Related
Im writing a selenium project from scratch using the PageObject.
The below code is failing because the selenium webdriver is not finding elements on the webpage .
This is the error i get :
java.lang.NullPointerException: Cannot invoke "org.openqa.selenium.SearchContext.findElement(org.openqa.selenium.By)" because "this.searchContext" is null
DriverBase.java :
In this class i setup the driver
package com.EbankingA11y.base;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import com.EbankingA11y.util.WebListener;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class DriverBase {
protected static final Logger LOG = (Logger) LogManager.getLogger(WebListener.class);
public static WebDriver driver;
public static Properties prop;
public static FileInputStream fis;
public DriverBase() {
prop = new Properties();
try {
fis = new FileInputStream("C:\\Users\\config.properties");
} catch (FileNotFoundException exception) {
exception.printStackTrace();
LOG.debug(" Error \n " +exception.getStackTrace());
}
try {
prop.load(fis);
} catch (IOException exception) {
exception.printStackTrace();
LOG.debug(" Error \n " +exception.getStackTrace());
}
}
public static void initialization () throws InterruptedException {
System.setProperty("webdriver.chrome.driver", prop.getProperty("WEB_DRIVER_PATH") );
//WebDriverManager.chromedriver().setup();
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setAcceptInsecureCerts(true);
driver = new ChromeDriver(chromeOptions);
driver.manage().window().maximize();
driver.get(prop.getProperty("URL"));
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
}
LoginPage.java
In this class i create all the element on the login page and all methods
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import com.EbankingA11y.base.DriverBase;
public class LoginPage extends DriverBase {
public LoginPage() {
PageFactory.initElements(DriverBase.driver, this);
}
#FindBy(name="username")
WebElement usernameTextBox;
#FindBy(name="password")
WebElement passwordTextBox;
#FindBy(xpath="//input[#value=\\\"Use 'Enter' to confirm\\\"]")
WebElement submitButton;
#FindBy(xpath="//button[#name='button']")
WebElement languageButton;
#FindBy(name="smsCode")
WebElement tokenTextBox;
public void performLogin () {
//WebDriverWait wait = new WebDriverWait(driver,30);
final String username = prop.getProperty("USERNAME");
final String password = prop.getProperty("PASSWORD");
System.out.println(username);
//wait.until(ExpectedConditions.visibilityOf(this.usernameTextBox));
usernameTextBox.clear();
passwordTextBox.clear();
usernameTextBox.sendKeys(username);
passwordTextBox.sendKeys(password);
submitButton.click();
//wait.until(ExpectedConditions.visibilityOf(this.tokenTextBox));
}
}
LoginPageTests.java :
In this class i write tests and i call methods from LoginPage.java Class
package com.EbankingA11y.testcases;
import java.io.IOException;
import org.openqa.selenium.WebDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.EbankingA11y.base.*;
import com.EbankingA11y.pages.LoginPage;
public class LoginPageTest extends DriverBase {
public LoginPageTest() throws IOException {
super();
}
LoginPage loginPage = new LoginPage();
#BeforeTest
public void setup() throws InterruptedException {
initialization();
}
#Test
public void login() {
loginPage.performLogin();
}
}
I found that i have to declare the pages in the before methods after the initilisation ()
public class LoginPageTest extends DriverBase {
public LoginPageTest() throws IOException {
super();
}
// here
LoginPage loginPage;
TokenPage tokenPage;
#BeforeTest
public void setup() throws InterruptedException {
initialization();
//here
loginPage = new LoginPage();
tokenPage = new TokenPage();
}
#Test
public void login() {
tokenPage = loginPage.performLogin();
}
}
This is just worked for me
I am writing the following code to resolve stale element reference in selenium. However, in eclipse it is giving me error on: final boolean retrying (By by)-this line.Also, first i wanted to use public boolean retrying(By by) instead of final boolean retrying (By by), but that was giving me error from the eclipse editor.
package com.TSOne.tcone;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class CalenderFfdriver {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver",
"/Users/owner/desktop/chromedriver");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.get("http://www.path2usa.com/travel-companions");
driver.findElement(By.cssSelector("#travel_date")).click();
List<WebElement>dates =driver.findElements(By.cssSelector(".day"));
System.out.println(dates.size());
final boolean retrying (By by) {
boolean result = false;
int attempts = 0;
while(attempts < 2) {
try {
driver.findElement(By.xpath("//*[#class='datepicker-
switch']")).click();
result = true;
break;
} catch(StaleElementReferenceException e) {
}
attempts++;
}
return;
}
WebElement navigator =driver.findElement(By.cssSelector("
[class='datepicker-days'] th[class='next']"));
while(!driver.findElement(By.cssSelector("[class='datepicker-days']
th[class='datepicker-switch']")).getText().contains("April"))
driver.findElement(By.cssSelector("[class='datepicker-days']
th[class='next']")).click();
for(int i=0;i<dates.size();i++) {
String text=dates.get(i).getText();
if(text.equalsIgnoreCase("23"))
dates.get(i).click();
}
}
}
Define final boolean retrying (By by) method outside of your main method and it should work.
package ee.sims;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class CalederFfdriver {
private static WebDriver driver = new ChromeDriver();
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver",
"/Users/owner/desktop/chromedriver");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.get("http://www.path2usa.com/travel-companions");
driver.findElement(By.cssSelector("#travel_date")).click();
List<WebElement>dates =driver.findElements(By.cssSelector(".day"));
System.out.println(dates.size());
WebElement navigator =driver.findElement(By.cssSelector("[class='datepicker-days'] th[class='next']"));
while(!driver.findElement(By.cssSelector("[class='datepicker-days'] th[class='datepicker-switch']")).getText().contains("April"))
driver.findElement(By.cssSelector("[class='datepicker-days'] th[class='next']")).click();
for(int i=0;i<dates.size();i++) {
String text=dates.get(i).getText();
if(text.equalsIgnoreCase("23"))
dates.get(i).click();
}
}
final boolean retrying (By by) {
boolean result = false;
int attempts = 0;
while(attempts < 2) {
try {
driver.findElement(By.xpath("//*[#class='datepicker-switch']")).click();
result = true;
break;
} catch(StaleElementReferenceException e) {
}
attempts++;
}
// note that i replaced "return;" here because it was a syntax error
return result;
}
}
The code above has no compilation errors.
This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 5 years ago.
I am new to Keyword Driven approach for selenium. I am getting NullPointerException while running below ExecuteTest.java
Folder Structure
Folder structure
Object.txt
Object.txt
TestCase.xlsx
TestCase.xlsx
Error Screenshot
Screenshot1
Screenshot2
Adding Debug screenshots
screenshot1
screenshot2
screenshot3
ReadGuru99Excel.java
import org.apache.poi.ss.usermodel.Sheet;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
public class ReadGuru99ExcelFile {
public Sheet readExcel (String filePath,String fileName, String sheetName)throws IOException{
File file = new File(filePath+"\\"+fileName);
FileInputStream inputStream = new FileInputStream(file);
Workbook guru99Workbook = null;
String fileExtensionName = fileName.substring(fileName.indexOf("."));
if(fileExtensionName.equals(".xlsx")){
guru99Workbook = new XSSFWorkbook(inputStream);
} else if(fileExtensionName.equals(".xls")) {
guru99Workbook = new HSSFWorkbook(inputStream);
}
Sheet guru99Sheet =guru99Workbook.getSheet(sheetName);
return guru99Sheet;
}
}
ReadObject.Java
package operation;
import java.util.Properties;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.File;
public class ReadObject {
Properties p = new Properties();
public Properties getObjectRepository()throws IOException{
InputStream stream = new FileInputStream(new File (System.getProperty("user.dir")+"\\src\\objects\\object.txt"));
p.load(stream);
return p;
}
}
UIOperation.java
package operation;
import org.openqa.selenium.WebDriver;
import java.util.Properties;
import org.openqa.selenium.By;
public class UIOperation {
WebDriver driver ;
public UIOperation(WebDriver driver){
this.driver = driver;
}
public void perform(Properties p, String operation, String objectName, String objectType, String value) throws Exception{
System.out.println("");
switch(operation.toUpperCase()){
case "CLICK":
driver.findElement(this.getObject(p, objectName, objectType)).click();
break;
case "SETTEXT":
driver.findElement(this.getObject(p, objectName, objectType)).sendKeys(value);
break;
case "GOTOURL":
driver.get(p.getProperty(value));
break;
case "GETTEXT":
driver.findElement(this.getObject(p, objectName, objectType)).getText();
break;
default:
break;
}
}
private By getObject(Properties p, String objectName, String objectType) throws Exception{
if(objectType.equalsIgnoreCase("XPATH")){
return By.xpath(p.getProperty(objectName));
}else if(objectType.equalsIgnoreCase("CLASSNAME")){
return By.className(p.getProperty(objectName));
}else if(objectType.equalsIgnoreCase("NAME")){
return By.name(p.getProperty(objectName));
}else if(objectType.equalsIgnoreCase("CSS")){
return By.cssSelector(p.getProperty(objectName));
}else if(objectType.equalsIgnoreCase("LINK")){
return By.linkText(p.getProperty(objectName));
}else if(objectType.equalsIgnoreCase("PARTIALLINK")){
return By.partialLinkText(p.getProperty(objectName));
}else{
throw new Exception("Wrong object type");
}
}
}
ExecuteTest.java
package testcases;
import java.util.Properties;
import operation.ReadObject;
import org.testng.annotations.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.MarionetteDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import operation.UIOperation;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Row;
import excelExportAndFileIO.ReadGuru99ExcelFile;
public class ExecuteTest {
#Test
public void testLogin()throws Exception{
/**
* System.setProperty("webdriver.gecko.driver", "E:\\Selenium-2017\\geckodriver-v0.18.0-win64\\geckodriver.exe");
* //Now you can Initialize marionette driver to launch firefox
* DesiredCapabilities capabilities = DesiredCapabilities.firefox();
* capabilities.setCapability("marionette", true);
* WebDriver driver = new RemoteWebdriver(capabilities);
*
* WebDriver webdriver = new FirefoxDriver();
**/
WebDriver driver;
System.setProperty("webdriver.chrome.driver","E:\\Selenium-2017\\chromedriver_win32\\chromedriver.exe");
driver = new ChromeDriver();
ReadGuru99ExcelFile file = new ReadGuru99ExcelFile();
ReadObject object = new ReadObject();
Properties allObjects = object.getObjectRepository();
UIOperation operation = new UIOperation(driver);
Sheet guru99Sheet = file.readExcel(System.getProperty("user.dir")+"\\test-output","TestCase.xlsx","KeywordFramework");
int rowCount =guru99Sheet.getLastRowNum()-guru99Sheet.getFirstRowNum();
System.out.println("first step clear");
for(int i = 0;i<rowCount+1; i++){
Row row =guru99Sheet.getRow(i);
System.out.println("2nd clear");
if(row.getCell(0).toString().length()==0){
System.out.println("4nd clear");
System.out.println(row.getCell(1).toString()+"-----"+row.getCell(2).toString()+"----"+row.getCell(3).toString()+"---"+row.getCell(4).toString());
System.out.println("3rd clear");
operation.perform(allObjects, row.getCell(1).toString(), row.getCell(2).toString(), row.getCell(3).toString(), row.getCell(4).toString());
} else
System.out.println("New Testcase->" + row.getCell(0).toString()+"Started");
System.out.println("testerassumption");
}
}
}
First of all, please see this wonderful post about NullPointerException and how to fix it.
In your case, the stacktrace points the NullPointerException to be occuring at line 49 of the code in ExecuteTest.java, which points to this line of code
operation.perform(allObjects, row.getCell(1).toString(), row.getCell(2).toString(), row.getCell(3).toString(), row.getCell(4).toString());
The issue here is that when you're trying to convert the contents of the cell in the getCell() method to a String, if there is nothing in the cell, then there would always be a NullPointerException.
You can either place a != null check before every cell or add a " " for every toString() method, like
operation.perform(allObjects, (row.getCell(1)+"").toString(), (row.getCell(2)+"").toString(), (row.getCell(3)+"").toString(), (row.getCell(4)+"").toString());
I'm trying to use following code :-
driver.findElement(By.xpath(".//*[#id='attach0']")).sendKeys("first path"+"\n"+"second path""+"\n"third path");
I didn't get result.
you can use AutoIT or JAVA code. Below i have used both for your reference. Try anyone of them
import java.io.IOException;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class AutoITforUpload {
private static WebDriver driver;
private static WebDriverWait waitForElement;
#FindBy(css = "span.btn.btn-success.fileinput-button")
private WebElement Add_files_btn;
#BeforeClass
public static void setUp() {
DesiredCapabilities desicap = new DesiredCapabilities();
System.setProperty("webdriver.chrome.driver", "D:/WorkSpace/Driver/chromedriver.exe");
desicap = DesiredCapabilities.chrome();
driver = new ChromeDriver(desicap);
driver.manage().window().maximize();
driver.get("https://blueimp.github.io/jQuery-File-Upload/");
waitForElement = new WebDriverWait(driver, 30);
}
#Test
public void AutoitUpload() {
// String filepath =
// "D:/Mine/GitHub/BasicProgramLearn/AutoItScript/unnamed.png";
WebElement btn = driver.findElement(By.cssSelector("span.btn.btn-success.fileinput-button"));
String file_dir = System.getProperty("user.dir");
String cmd = file_dir + "\\AutoItScript\\unnamed.png";
System.out.println("File directory is " + file_dir);
try {
// Using ordinary
Thread.sleep(3000);
for(int i=0;i<3;i++) //multiple times upload ;
driver.findElement(By.xpath("//*[#id='fileupload']/div/div[1]/span[1]/input")).sendKeys(cmd);
//use any String Array for multiple files
waitForElement(btn);
btn.click();
Thread.sleep(3000);
System.out.println(file_dir + "/AutoItScript/FileUploadCode.exe");
Runtime.getRuntime().exec(file_dir + "\\AutoItScript\\ChromeFileUpload.exe" + " " + cmd);
} catch (InterruptedException | IOException e) {
e.printStackTrace();
}
}
#AfterClass
public static void TearDown() {
try {
Thread.sleep(5000);
driver.quit();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
private void waitForElement(WebElement vElement) {
waitForElement.until(ExpectedConditions.visibilityOf(vElement));
}
}
The code in AutoIt is
#include<IE.au3>
If $CmdLine[0] < 2 Then
$window_name="Open"
WinWait($window_name)
ControlFocus($window_name,"","Edit1")
ControlSetText($window_name,"","Edit1",$CmdLine[1])
ControlClick($window_name,"","Button1")
EndIf
Hope this gives you an idea
I have successfully created a data driven framework with selenium 1 and trying to do the same using selenium 2 (WebDriver). I was doing some basic R and D. My code is as below.
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
import org.testng.annotations.*;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.io.File;
import jxl.*;
#SuppressWarnings("unused")
public class FirstTestusingWebDriver {
private WebDriver driver;
private String baseUrl="http://www.google.co.in";
private StringBuffer verificationErrors = new StringBuffer();
#BeforeClass
public void setUp() throws Exception {
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
#DataProvider(name="DP")
Object[] createData(){
String[] testData = {"Cheese", "Sudeep"};
System.out.println("Data is getting created");
return testData;
}
#Test(dataProvider="DP")
public void testUntitled(String testData) throws Exception {
driver.get("http://www.google.co.in/");
driver.findElement(By.id("lst-ib")).clear();
driver.findElement(By.id("lst-ib")).sendKeys(testData);
driver.findElement(By.name("btnG")).click();
driver.findElement(By.linkText("Cheese - Wikipedia, the free encyclopedia")).click();
}
#AfterClass
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
}
But with this code, the test is not running. Firefox opens and closes while running the test as testNG. Can anyone suggest a proper way to go about it or how to make this work.
just do a slight amendment in ur createData() i.e
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
import org.testng.annotations.*;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.io.File;
#SuppressWarnings("unused")
public class FirstTestusingWebDriver {
private WebDriver driver;
private String baseUrl="http://www.google.co.in";
private StringBuffer verificationErrors = new StringBuffer();
#BeforeClass
public void setUp() throws Exception {
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
#DataProvider(name="DP")
Object[][] createData(){
String[] testData = {"Cheese", "Sudeep"};
System.out.println("Data is getting created");
return new Object[][]{{testData[0]+testData[1]}};
}
#Test(dataProvider="DP")
public void testUntitled(String testData) throws Exception {
driver.get("http://www.google.co.in/");
driver.findElement(By.id("lst-ib")).clear();
driver.findElement(By.id("lst-ib")).sendKeys(testData);
driver.findElement(By.name("btnG")).click();
//driver.findElement(By.linkText("Cheese - Wikipedia, the free encyclopedia")).click();
}
#AfterClass
public void tearDown() throws Exception {
//driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}}
now it will work fine..