首页 > 解决方案 > 无法在 webdriverio Cucumber 框架中为表单字段设置值

问题描述

我对 webdriver io 和 cucumber 框架非常陌生。尝试使用应用程序的登录屏幕进行我的第一次测试。我可以调用浏览器并加载网站。但是当我尝试为登录字段设置值时,它会引发以下错误并中止

“执行登录时出错:使用默认用户登录:当我使用默认用户登录时”浏览器。$(...).setValue 不是函数”

我试图安装同步包并在配置文件中将同步设置为 true。我无法让它工作。请帮忙 !

这是我的配置文件

出口.config = {

//
// ====================
// Runner Configuration
// ====================
//
// WebdriverIO allows it to run your tests in arbitrary locations (e.g. locally or
// on a remote machine).
runner: 'local',
//
path: '/wd/hub',

specs: [
    './features/*.feature'
],
// Patterns to exclude.
exclude: [
    // 'path/to/excluded/files'
],
//

maxInstances: 10,

capabilities: [{

    // maxInstances can get overwritten per capability. So if you have an in-house Selenium
    // grid with only 5 firefox instances available you can make sure that not more than
    // 5 instances get started at a time.
    maxInstances: 5,
    //
    browserName: 'firefox',
    // If outputDir is provided WebdriverIO can capture driver session logs
    // it is possible to configure which logTypes to include/exclude.
    // excludeDriverLogs: ['*'], // pass '*' to exclude all driver session logs
    // excludeDriverLogs: ['bugreport', 'server'],
}],

logLevel: 'info',
sync:true,
bail: 0,

baseUrl: '********************',
//
// Default timeout for all waitFor* commands.
waitforTimeout: 10000,
//
// Default timeout in milliseconds for request
// if browser driver or grid doesn't send response
connectionRetryTimeout: 90000,
//
// Default request retries count
connectionRetryCount: 3,

services: ['selenium-standalone'],


framework: 'cucumber', 


cucumberOpts: {
    requireModule: ['@babel/register'],// <string[]> ("extension:module") require files with the given EXTENSION after requiring MODULE (repeatable)
    require: ['./step-definitions/*.js'],       // <string[]> (file/dir) require files before executing features

    backtrace: false,   // <boolean> show full backtrace for errors
    dryRun: false,      // <boolean> invoke formatters without executing steps
    //compiler: ['js:babel-core/register'],
    failFast: false,    // <boolean> abort the run on first failure
    format: ['pretty'], // <string[]> (type[:path]) specify the output format, optionally supply PATH to redirect formatter output (repeatable)
    snippets: true,     // <boolean> hide step definition snippets for pending steps
    source: true,       // <boolean> hide source uris
    profile: [],        // <string[]> (name) specify the profile to use
    strict: false,      // <boolean> fail if there are any undefined or pending steps
    tagExpression: '',  // <string> (expression) only execute the features or scenarios with tags matching the expression
    timeout: 60000,     // <number> timeout for step definitions
    ignoreUndefinedDefinitions: false, // <boolean> Enable this config to treat undefined definitions as warnings.
},

标签: node.jscucumberwebdriver-io

解决方案


欢迎来到堆栈溢出。您在问题中提供的相关细节越多,您就越早得到答案。

据我所知,问题可能是以下三个中的任何一个。

1) setValue 不适用于您的元素,因为您没有选择合适的元素。您可以尝试改进您的选择器/定位器。

2)您可以尝试点击文本区域并尝试使用keys api。

3)您不需要将路径属性设置为该值。您可以将其保留为默认“/”。

参考: GitHub 上的示例repo


推荐阅读