使用的框架-量角器 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它执行的新联接按钮。但是,当Scenario: firstPurchasePopup login button
再次启动应用程序时,由于再次关闭了驱动程序,该驱动程序没有再次启动,因此无法正常工作。
要启动它,我需要创建beforeTest,我很难编写代码
答案 0 :(得分:0)
我没有将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
一个。
您尝试过吗?
答案 1 :(得分:0)
@全部 感谢您的输入@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();
});