当前位置: 首页 > 知识库问答 >
问题:

从属性文件传递cucumber特征文件的datatable中的值

岳奇逸
2023-03-14
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
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)

共有1个答案

赫连正初
2023-03-14

年龄=45岁

问题是,它将值作为int读取,而不是字符串。将其更改为

“45”

 类似资料:
  • 我已经创建了一些cucumber测试步骤和一个小的Cucumber测试用例,我用JUnit运行它,如下所示: Cucumber功能文件现在从类路径位置自动加载,

  • 我是cucumber领域的新手,我只想为我的场景的上下文描述一个聚合。我有一个模型和如下所示的DataTransferObject,我想编写一个返回JSON的REST Api。 但是,我如何编写给定的部分并以一种清晰的方式描述对象,即有三个不同的具有聚合的类?

  • 在cucumber测试中,我想在不改变特性文件的情况下跳过一些特性文件,比如添加额外的标记。虽然标签可以排除功能文件运行,但我不能修改这些文件。是否有方法在maven pom.xml中进行配置?或者我可以使用带有特殊特性参数的@cucumberoptions吗? 一种方法是使用Maven插件为每个特性文件生成一个Junit Runner类。然后,通过,我们可以指定排除或包含以排除或包含那些Juni

  • 我已经写了我的firsy cucumber特征文件。当我将功能文件作为Cucumber功能运行时,会出现以下错误 “警告:cucumber-jvm的--format选项不推荐使用。请改用--plugin。”-我在我的@CucumberOptions of runner类中使用了“plugin”,但仍然得到相同的错误 场景:验证登录页面#c:/selenium/regressiontest/modu

  • 我必须在一次登录中运行多个案例的功能文件。对于ex: 场景:当用户使用“用户名”和“密码”登录并且用户检查“on”和用户检查“on”时,检查总计 示例: |用户名|密码|金额1|日期1|金额2|日期2|... 我需要在一次登录中检查日期金额,而在我的场景中,每次登录数据表中的每个条目。我如何实现它? 相反,我希望这样: 当用户使用“用户名”和“密码”登录时 示例: |用户名|密码|...只使用一次

  • 问题/错误------------------------------------------------ 1方案([33m1未定义[0m)3步骤([33m3未定义[0m)0m0.000s 您可以使用以下代码段实现缺少的步骤: