0
votes

I want to pass the values of the variables in the datatable of feature files from properties file. This is what i had written but it gives me error ..complete stack trace below

org.openqa.selenium.WebDriverException: unknown error: keys should be a string

featurefile

Scenario: Capture a user and check user details

Given Opens the userdetails, searches for 'name' and clicks on 'enter'
When Enters the following into the various fields 'Fname', 'Lname', 'Mname', 'Age' and  'Language'
  |fname1|lname1|mname1|age1| language1|
  |fname |lname|mname|age|language|

Step Definition :

@When("Enters the following into the various fields '(.*)', '(.*)', '(.*)', '(.*)', '(.*)', '(.*)' and '(.*)'")
public void enters_the_following_into_the_various_fields_and(String fname1, String lname1, String mname1, String age1, String language1, DataTable dataTable) throws IOException {
    somepageclass = new somepageclass(driver);
    somepageclass.enterUserDetails(fname1, lname1, mname1, age1, language1);

    Properties file :

    fname = Ricky
    lname = Peters
    mname = M
    age = 45
    language = English

    Page methods :

    public void enterUserDetails(String fname1, String lname1, String mname1, String age1, String language1) throws IOException {
    element.sendKeys(loadData().getProperty(fname1));  //loaddata() is reading the property file} 

    Stack Trace :
org.openqa.selenium.WebDriverException: unknown error: keys should be a string

(Session info: chrome=69.0.3497.100) (Driver info: chromedriver=2.42.591088 (7b2b2dca23cca0862f674758c9a3933e685c27d5),platform=Windows NT 10.0.16299 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 0 milliseconds Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z' System info: host: 'BNEPC9455', ip: '172.28.2.6', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_45' Driver info: org.openqa.selenium.chrome.ChromeDriver Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 2.42.591088 (7b2b2dca23cca0..., userDataDir: C:\Users\Bankimp\AppData\Lo...}, cssSelectorsEnabled: true, databaseEnabled: false, goog:chromeOptions: {debuggerAddress: localhost:65524}, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, unexpectedAlertBehaviour: , unhandledPromptBehavior: , version: 69.0.3497.100, webStorageEnabled: true} Session ID: 45d808a230024e3671c80a92214fb8c0

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:276)
at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:100)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:51)
at com.sun.proxy.$Proxy13.sendKeys(Unknown Source)
2

2 Answers

0
votes

age = 45

is the problem, it's reading the value as an int, not a string. change it to

"45"

0
votes

I did get this working.

So I did this by creating a userdata class with getter and setter. In setter I'm reading the prop file to get the values of the cucumber datatable parameter fname and getting it in method to use the vaue