我的代码运行正常,没有任何故障,但是没有执行任何单击或sendkey或任何其他操作。.浏览器自动关闭,甚至在使用console.log时,它不响应browser.sleep命令。文字,但元素操作不起作用
var page=require("..\\src\\StepDefFiles\\testpage.js");
var test=function(){
Given('Load the URL', function () {
page.browserInit();
});
Given('Get the Title', function () {
// Write code here that turns the phrase above into concrete actions
browser.getTitle().then(function(title){
console.log(title);
})
});
Then('Login in to the account', function () {
page.gmailLink();
});
Then('validate the home page', function () {
browser.getTitle().then(function(Title){
if(Title.indexOf("sign in")!=-1){
console.log(Title);
}
})
});
}
module.exports=new test();
var testPage=function(){
this.browserInit=function(){
browser.ignoreSynchronization=true;
browser.get("https://google.com");
browser.sleep(5000);
browser.manage().window().maximize();
browser.sleep(5000);
}
this.gmailLink=function(){
element(By.xpath("//a[text()='Gmail']")).click();
}
}
module.exports=new testPage();
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
getPageTimeout: 60000,
allScriptsTimeout: 500000,
framework: 'custom',
// path relative to the current config file
frameworkPath: require.resolve('C:\\Users\\DELL\\node_modules\\protractor-cucumber-framework'),
capabilities: {
'browserName': 'chrome'
},
// Spec patterns are relative to this directory.
specs: [
'..\\Protractor_Cucumber\\src\\FeatureFiles\\Test.feature'
],
cucumberOpts: {
require: '..\\Protractor_Cucumber\\src\\StepDefFiles\\stepDef.js',
tags: false,
profile: false,
'no-source': true
},
onPrepare: function () {
const {Given, Then, When, Before} = require('C:\\Users\\DELL\\node_modules\\cucumber');
global.Given = Given;
global.When = When;
global.Then = Then;
global.Before = Before;
}
};
Feature: Title of your feature
I want to use this template for my feature file
Scenario: Title of your scenario
Given Load the URL
And Get the Title
Then Login in to the account
And validate the home page
21:41:37] I/launcher - Running 1 instances of WebDriver
[21:41:37] I/hosted - Using the selenium server at http://localhost:4444/wd/hub
.....
1 scenario (1 passed)
4 steps (4 passed)
0m00.030s
Google
[21:41:46] I/launcher - 0 instance(s) of WebDriver still running
[21:41:46] I/launcher - chrome #01 passed
如果有人能够回答这个问题,对我来说将是一个很大的帮助
答案 0 :(得分:0)
按如下所示更改您的StepDef文件:
var page = require("../src/StepDefFiles/testpage.js");
Given('Load the URL', function() {
return page.browserInit();
});
Given('Get the Title', function() {
// Write code here that turns the phrase above into concrete actions
return browser.getTitle().then(function(title) {
console.log(title);
})
});
Then('Login in to the account', function() {
return page.gmailLink();
});
Then('validate the home page', function() {
return browser.getTitle().then(function(Title) {
if (Title.indexOf("sign in") != -1) {
console.log(Title);
}
})
});