protractor - 如何使用打字稿(量角器+黄瓜)执行 beforeTest 和 afterTest 方法
问题描述
使用的框架 - 量角器 BDD - 黄瓜语言 - 打字稿
- 现在我已经实现了框架,并且测试场景也可以使用量角器正常运行。
但是我面临的问题是,当我编写另一个黄瓜场景时,我的测试失败了,说“会话已终止或未启动”
- 上述失败是因为当我的第一个黄瓜场景启动时,appium 服务器在我的配置中启动,最后我关闭服务器/驱动程序
- 现在我编写了另一个测试场景,因为 cucumber 独立于每个场景,当 sec 启动时它不会再次进行配置。现在我需要一个 beforeTest 方法来调用。
所以我不确定如何在打字稿中实现它,因为我是新手。
尝试了相同的java方式概念,但没有成功。那里有 javascript 的示例,但仍然没有帮助我。
- 尝试创建一个新的 util 文件夹并将我的 beforeTest 放在其中,但该函数没有在那里调用
- 尝试在我的配置文件中使用 beforeLaunch()with ,但仍然无法解决
我的配置文件:config.ts
export let config: Config = {
allScriptsTimeout: 40000,
getPageTimeout: 40000,
setDefaultTimeout: 60000,
defaultTimeoutInterval: 30000,
specs: [
// '../../utils/beforeEach.ts',
'../../features/*.feature',
],
onPrepare: () => {
Reporter.createDirectory(jsonReports);
tsNode.register({
project: './tsconfig.json'
});
},
multiCapabilities: [
androidPixel2XLCapability,
// iPhoneXCapability
],
framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
cucumberOpts: {
compiler: "ts:ts-node/register",
glue: ["steps"],
format: [
"json:./reports/json/cucumber_report.json",
],
require: ['supports/timeout.js', '../../stepdefinitions/*.ts'],
tags: "@firstPurchasePopup",
},
seleniumAddress: serverAddress,
onComplete: () => {
Reporter.createHTMLReport();
},
// =====
// Hooks
// =====
beforeTest: function () {
},
beforeLaunch(){
console.log("Before");
seleniumAddress: 'http://localhost:4723/wd/hub';
},
afterLaunch() {
console.log("After");
},
};
我的另一个 beforeEach.ts:这不起作用,但我累了并且不起作用。
import {After, AfterAll, Before} from "cucumber";
const serverAddress = 'http://localhost:4723/wd/hub';
import {beforeEach, afterEach, describe} from "selenium-webdriver/testing";
beforeEach(function () {
console.log("Before");
});
// });
afterEach(function () {
console.log("Before");
});
// let beforeEach: () => void;
// beforeEach = () => {
// console.log("Before Test");
// // config.multiCapabilities;
// seleniumAddress: serverAddress;
// };
//
// let afterEach: () => void;
// afterEach = () => {
// console.log("After Test");
// };
这是我的功能文件:bonus.feature
this is my feature file:
Background:
Given I launch the app
Then I should see the popup window for the Bonus
And I verify the UI
Then I tap on ok button
And The popup window should not be seen
@firstPurchasePopup
Scenario: firstPurchasePopup new join button
When I tap on the 'New ' button
And The popup window should not be seen
Then I navigate back from join page to home page
Then The popup window should not be seen
Then I close the app
@firstPurchasePopup
Scenario: firstPurchasePopup login button
And I tap on log in button on the initial screen
Then I navigate back from login page to home page
And The popup window should not be seen
Then I close the app
我希望我所写的场景能够一个接一个地执行,例如执行场景:firstPurchasePopup new join button 。但是,当它再次启动该应用程序一秒钟Scenario: firstPurchasePopup login button
时,由于驱动程序未再次启动,因此它无法正常工作,因为它已在上一个中关闭。要开始它,我需要创建 beforeTest 我很难编写代码
解决方案
我没有在 Cucumber 中使用 Protractor,但我已经将 Cucumber 和 Typescript 一起使用。cucumber.js
我通过在默认情况下在开始时加载的根目录中的文件解决了这个问题,看起来像这样:
var settings = "features/**/*.feature -r step-definitions/**/*.ts -r hooks/**/*.ts -r support/**/*.ts "
module.exports = {
"default": settings
}
但是,我认为在您的情况下,解决方案是将挂钩文件的路径添加到config.cucumberOpts.require
列表而不是config.specs
一个。
你试过了吗?
推荐阅读
- javascript - CSS 和 JS 文件有时无法在我们的 Wordpress 网站上加载
- unity3d - 如何在统一 3d 中单击“选项卡”按钮时聚焦输入字段
- angular - 如何使用 web api 和 angular 在表单提交上上传文件
- django - Django:我可以链接 2 个模型字段而不是模型类吗?
- react-native - React-native-tag-autocomplete:如何在建议列表中添加滚动条
- java - Java String spit 使用正则表达式和单个正斜杠,后面没有斜杠
- spring - Spring JPA:如何插入数据以使用@ManytoMany 关系连接多个表
- .net - .net 项目的 DLL 注入
- reactjs - 使用反应组件时间选择器时 value.format 不是一个功能
- vba - 选择整列VBA中的相邻单元格