【发布时间】:2022-01-08 12:51:35
【问题描述】:
我是 webdriverio 的新手并尝试在黄瓜框架中运行基本测试,当我运行测试浏览器时正在加载和打开网站,但它在第二步中失败(输入用户名和密码)
我试图寻找解决方案,但没有得到任何东西。你能帮我解决这个问题吗
GitHub:https://github.com/Jyoti2190-Test/webdrieriopractice/tree/master
注意:已经尝试添加 browser.pause(3000)。
请在下面找到代码
功能文件
Feature: To test the login functionality in "The Internet Herokuapp"
Background:
Given the user is on login page
Scenario: The one where user logs in using valid credentials
When the user enters username as "tomsmith" and password as "SuperSecretPassword!"
And clicks on login button
Then the user must navigate to secure area page displaying a message "You logged into a secure area!"
Scenario Outline: The one where user logs in using invalid credentials
When the user enters username as "<username>" and password as "<password>"
And clicks on login button
Then the user must remain on login page displaying a message "<errorMessage>"
Examples:
| username | password | errorMessage |
| james | SuperSecretPassword! | Invalid username! |
| tomsmith | SuperPassword! | Invalid password! |
PageObject 文件 (login.page.js)
class LoginPage {
get userNameTextBox() { return browser.element('#username'); }
get passwordTextBox() { return browser.element('#password'); }
get loginButton() { return browser.element('button[type="submit"]'); }
get loginPageElement() { return browser.element('div[class="example"] h2'); }
get messageElement() { return browser.element('#flash'); }
}
export default new LoginPage();
Step.js
import { Given, When, Then } from '@cucumber/cucumber';
const LoginPage = require('../pages/login.page');
const SecurePage = require('../pages/secure.page');
Given('the user is on login page', function () {
browser.url("https://the-internet.herokuapp.com/login");
expect(browser).toHaveTitle('The Internet');
});
When('the user enters username as {string} and password as {string}', function (username, password)
{
browser.pause(6000);
LoginPage.userNameTextBox.setValue(username);
LoginPage.passwordTextBox.setValue(password);
});
When('clicks on login button', function () {
LoginPage.loginButton.click();
});
Then('the user must navigate to secure area page displaying a message {string}', function (successMessage) {
expect(SecurePage.secureAreaElement).toExist();
expect(SecurePage.secureAreaElement).toHaveTextContaining('Secure Area');
expect(SecurePage.messageElement).toExist();
expect(SecurePage.messageElement).toHaveTextContaining(successMessage);
});
Then('the user must remain on login page displaying a message {string}', function (string) {
expect(LoginPage.loginPageElement).toExist();
expect(LoginPage.loginPageElement).toHaveTextContaining('Login Page');
expect(LoginPage.messageElement).toExist();
expect(LoginPage.messageElement).toHaveTextContaining(errorMessage);
});
**Error Log**
[0-0] Error in "0: When the user enters username as "tomsmith" and password as "SuperSecretPassword!""
TypeError: Cannot read properties of undefined (reading 'setValue')
at World.<anonymous> (..\Documents\WebDriverIO_Cucumber_Project\features\step-definitions\/step.js:13:31)
at World.executeAsync (..\Documents\WebDriverIO_Cucumber_Project\node_modules\@wdio\utils\build\shim.js:325:27)
at World.testFrameworkFnWrapper (..\WebDriverIO_Cucumber_Project\node_modules\@wdio\utils\build\test-framework\testFnWrapper.js:45:32)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at Object.wrapPromiseWithTimeout (..\Documents\WebDriverIO_Cucumber_Project\node_modules\@cucumber\cucumber\src\time.ts:56:10)
at Object.run (..\Documents\WebDriverIO_Cucumber_Project\node_modules\@cucumber\cucumber\src\user_code_runner.ts:86:16)
at Object.run (..\Documents\WebDriverIO_Cucumber_Project\node_modules\@cucumber\cucumber\src\runtime\step_runner.ts:50:20)
at TestCaseRunner.invokeStep (..\Documents\WebDriverIO_Cucumber_Project\node_modules\@cucumber\cucumber\src\runtime\test_case_runner.ts:130:12)
at TestCaseRunner.runStep (..\Documents\WebDriverIO_Cucumber_Project\node_modules\@cucumber\cucumber\src\runtime\test_case_runner.ts:307:20)
at ..\Documents\WebDriverIO_Cucumber_Project\node_modules\@cucumber\cucumber\src\runtime\test_case_runner.ts:210:36
"keywords": [],
"author": "Jyoti Singhal",
"license": "ISC",
"devDependencies": {
"@babel/cli": "^7.6.4",
"@babel/core": "^7.6.4",
"@babel/preset-env": "^7.6.3",
"@babel/register": "^7.6.2",
"@wdio/allure-reporter": "^7.16.11",
"@wdio/cli": "^7.16.12",
"@wdio/cucumber-framework": "^7.16.12",
"@wdio/local-runner": "^7.16.12",
"@wdio/selenium-standalone-service": "^7.16.11",
"@wdio/spec-reporter": "^7.16.11",
"chromedriver": "^97.0.0"
【问题讨论】:
-
你使用的nodejs和webdriverio是什么版本的?
-
@Raju 节点版本:v16.13.1 & webdriverio cli:7.6.12
-
我会尽快添加的
标签: javascript reactjs cucumber webdriver-io