我想从属性文件传递特征文件的数据表中的变量值。这是我写的,但是给了我下面的错误..complete stack trace
org.openqa.selenium.WebDriverException:未知错误:密钥应为字符串
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
(会话信息:chrome = 69.0.3497.100) (驱动程序信息:chromedriver = 2.42.591088(7b2b2dca23cca0862f674758c9a3933e685c27d5),platform = Windows NT 10.0.16299 x86_64)(警告:服务器未提供任何堆栈跟踪信息) 命令持续时间或超时:0毫秒 构建信息:版本:'3.14.0',修订版本:'aacccce0',时间:'2018-08-02T20:19:58.91Z' 系统信息:主机:'BNEPC9455',ip:'172.28.2.6',os.name:'Windows 8.1',os.arch:'amd64',os.version:'6.3',java.version:'1.8.0_45 ' 驱动程序信息:org.openqa.selenium.chrome.ChromeDriver 功能{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:正常,平台:XP,平台名称:XP,可旋转:false,setWindowRect:true,takesHeapSnapshot:true,takesScreenshot:true,意外AlertBehaviour:,unhandledPromptBehavior:,版本:69.0.3497.100,webStorageEnabled:true} 会话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)
答案 0 :(得分:0)
年龄= 45
是问题所在,它以int而不是字符串的形式读取值。将其更改为
“ 45”
答案 1 :(得分:0)
我确实做到了。
因此,我通过使用getter和setter创建一个userdata类来做到这一点。在setter中,我正在读取prop文件以获取黄瓜数据表参数fname的值,并将其获取使用vaue的方法