使用的框架-量角器BDD-黄瓜语言-打字稿
但是我面临的问题是当我编写另一个黄瓜方案时,我的测试失败,提示'会话已终止或未开始'
所以我不确定如何在打字稿中实现该功能,因为我是新手。
尝试过与Java方式相同的概念,但无法解决。那里有一些关于javascript的示例,但仍然没有帮助我。
我的配置文件: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
我希望我编写的脚本能够依次执行这两个脚本,就像execute Scenario:firstPurchasePopup new join button一样。但是当它再次启动该应用程序几秒钟时Scenario: firstPurchasePopup login button
不起作用,因为该驱动程序没有再次启动,因为它在上一个版本中已关闭。要启动它,我需要创建beforeTest,我很难编写代码]
我没有将Protractor与Cucumber一起使用,但是我一起使用了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
一个。
您尝试过吗?
@全部感谢您的输入@mhyphenated我发现不是在配置内部使用,而是尝试在hooks.ts中使用before和after,除了调用服务器之外,我实际上没有真正调用android驱动程序,如下所示beforeTest:function(){
beforeTest: function () {
},
beforeLaunch(){
console.log("Before");
seleniumAddress: 'http://localhost:4723/wd/hub';
},
hooks.ts
import { AndroidDriver } from "appium/node_modules/appium-android-driver";
let driver:AndroidDriver, defaultCaps;
driver = new AndroidDriver();
Before(function () {
// This hook will be executed before all scenarios
browser.ignoreSynchronization = false;
browser.manage().timeouts().implicitlyWait(500);
let defaultCaps = config.multiCapabilities[0];
console.log("defaultCaps = ", defaultCaps );
driver.createSession(defaultCaps);
driver.defaultWebviewName();
});