Driver class:
package com.deere.gmsr;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Driver {
public static WebDriver driver;
public static WebDriver openBrowser(String browserName, String url) throws InterruptedException {
if(browserName.equals("chrome")) {
System.setProperty("webdriver.chrome.driver", "D:\\chromedriver\\chromedriver.exe");
driver=new ChromeDriver();
driver.manage().window().maximize();
driver.get(url);
driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
return driver;
}else
if(browserName.equals("IE")) {
System.setProperty("webdriver.chrome.driver", "D:\\chromedriver\\chromedriver.exe");
driver=new ChromeDriver();
driver.manage().window().maximize();
// driver.get(url);
Thread.sleep(5000);
return driver;
}else
if(browserName.equals("Firefox")) {
System.setProperty("webdriver.chrome.driver", "D:\\chromedriver\\chromedriver.exe");
driver=new ChromeDriver();
driver.manage().window().maximize();
// driver.get(url);
Thread.sleep(5000);
return driver;
}
return driver;
}
public static WebDriver getDriver(){
try{
if(driver == null) {
PropertiesFileReader obj=new PropertiesFileReader();
Properties properties=obj.getproperty();
openBrowser(properties.getProperty("browserName"), properties.getProperty("URL"));
}
}catch(Exception e) {
e.printStackTrace();
}
return driver;
}
public void quitDriver() {
driver.close();
driver.quit();
}
}
Properties :
package com.deere.gmsr;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
public class PropertiesFileReader {
public Properties getproperty() throws IOException {
FileInputStream inputstream=null;
Properties properties=new Properties();
try {
properties.load(new FileInputStream("Configuration/config.properties"));
}catch(Exception e) {
System.out.println("Exception " +e);
}
return properties;
}
}
Loginpage:
package com.deere.gmsr.page;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;
import org.openqa.selenium.support.PageFactory;
public class LoginPage {
// WebDriver driver;
public LoginPage(WebDriver driver) {
// this.driver=driver;
PageFactory.initElements(driver, this);
}
@FindBy(how=How.ID,using="username")
public WebElement usernametexbox;
@FindBy(how=How.ID,using="-password")
public WebElement passwordtextbox;
@FindBy(how=How.ID,using="signin-")
public WebElement signin;
/* @FindBy(how=How.XPATH,using="//button[@class='btn btn-primary']")
public WebElement acceptbutton; */
public void enter_username(String username) {
usernametexbox.clear();
usernametexbox.sendKeys(username);
usernametexbox.getText();
}
public void enter_password(String password) {
passwordtextbox.clear();
passwordtextbox.sendKeys(password);
}
public void clickToSigninbutton() {
signin.click();
}
/* public void clickToAcceptbutton() {
acceptbutton.click();
} */
public void fill_LoginDetails() {
enter_username("ggggg");
enter_password("hhhhh");
}
}
Logintestcase:
package com.deere.gmsr.testcase;
import org.openqa.selenium.WebDriver;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
import com.deere.gmsr.Driver;
import com.deere.gmsr.page.LoginPage;
public class LoginTestcase {
public static WebDriver driver;
public LoginPage loginpage=new LoginPage(Driver.getDriver());
@Test
public void enter_LoginDetails() {
loginpage.fill_LoginDetails();
/* Properties properties=obj.getproperty();
driver=BrowserUtility.openBrowser(properties.getProperty("browserName"),properties.getProperty("URL")); */
}
@Test
public void click_on_sign_in_button() {
loginpage.clickToSigninbutton();
System.out.println("Sign-In successfully");
}
}
testng xml:
<suite name="GMSR">
<test name="LoginTest">
<classes>
<class name="com.deere.gmsr.testcase.LoginTestcase" />
</classes>
</test>
</suite>
TestData
what you are sending may be in your cucumber framework you was sending correct value.