即使该方法正在执行,我的代码也未对浏览器执行任何操作

时间:2019-03-26 04:44:59

标签: node.js selenium-webdriver protractor cucumber cucumberjs

我正在尝试在我的项目中实现量角器-黄瓜框架。当我执行代码时,方法正在执行,但是方法中的代码未执行。我的意思是,当我尝试单击或在字段中输入数据或通过浏览器暂停浏览器执行时,睡眠这些操作正在执行,并且我的脚本没有失败。

我的stepDef文件

var login=require("../src/main/java/Utilities/LoginPage.js");


 var test1=function(){ 


   var local=this;

      Given('Open the Browser', function () {
       console.log("first executed")
       browser.ignoreSynchronization=true;
       login.get("https://abhibus.com");

     });

     Given('Load the URL', function () {
       // Write code here that turns the phrase above into concrete actions
       console.log("second executed");
         browser.getTitle().then(function(title){
             console.log(title+" title of the webpage");
         });
         browser.sleep(5000);
     });


     Then('Get the Title of the webpage', function () {
       // Write code here that turns the phrase above into concrete actions  
       console.log("third executed");
     browser.driver.findElement(By.id("LoginForm_username")).sendKeys("admin@admin@bkcms.com");
      browser.driver.findElement(By.id("Loginform_password")).sendKeys("test");
     //  login.loginpage("admin@admin@bkcms.com","test");
    browser.sleep(3000);
     });


    }
    module.exports=new test1();

我的特征文件

Feature: this to test new Application

Scenario: This a new Scenario

Given This is to load URL

And do some action on webpage

Then Print the title of the webpage

我的配置文件

exports.config = {

seleniumAddress: 'http://localhost:4444/wd/hub',
getPageTimeout: 60000,
allScriptsTimeout: 500000,
framework: 'custom',
// path relative to the current config file
frameworkPath: require.resolve('protractor-cucumber-framework'),
capabilities: {
    'browserName': 'chrome'
},

// Spec patterns are relative to this directory.
specs: [
    '../Protractor.Cucumber.Test/src/main/java/featureFiles/Test.feature'
],

cucumberOpts: {
    require: '../Protractor.Cucumber.Test/src/test/java/StepDefinitions/test1.js',
    tags: false,
    profile: false,
    'no-source': true
},
 onPrepare: function () {
const {Given, Then, When, Before} = require('cucumber');
global.Given = Given;
global.When = When;
global.Then = Then;
global.Before = Before;
  }
};

代码结果

  

I /启动程序-运行1个WebDriver实例

     

[09:56:12]我/托管-在以下位置使用硒服务器   http://localhost:4444/wd/hub

     

首先执行

     

。秒执行

     

。第三次执行

     

..

     

1个场景(1个通过)

     

3步(已通过3步)

     

0m00.008s

登录页面代码

var properties=PropertiesReader("../Protractor.Cucumber.Test/src/main/java/Utilities/Object.properties");
var login=function(){

    var user=by.xpath("//input[@id='LoginForm_username']");
    var pass=by.id("LoginForm_password");
    var submit=by.id("login_submit");
    var local=this;

    this.Init=function(){
        local.username();
        local.password();
        local.Submit();
    }

    this.get=function(){
        browser.get(properties.get("url"));
        browser.manage().window().maximize();
        browser.driver.sleep(5000);
    }

    this.username=function(){
         return element(user);
    }

    this.password=function(){
        return element(pass);
    }

    this.Submit=function()
    {
    return element(submit);
    }

     this.loginpage=function(Username,Password){
         console.log("entred in to login method")
           var userfield=local.username();
           userfield.sendKeys(Username);
           var passfield=local.password();
           passfield.sendKeys(Password);
           var button=local.Submit();
           button.click();
           browser.driver.sleep(5000);
         }

}
module.exports=new login();

0 个答案:

没有答案