量角器通过我的测试而不执行'it'块 [英] Protractor passes my tests without executing the 'it' blocks

查看:100
本文介绍了量角器通过我的测试而不执行'it'块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近尝试在此帖子之后使用Page Object Model和Protractor
http://engineering.wingify.com/posts/angularapp-e2e-testing-with-protractor/



但是,当我运行我的测试时,我的块不会被执行。



以下是我的登录页面对象

< pre class =snippet-code-js lang-js prettyprint-override> / *文件名:loginPage.js * / var loginPage = function(){'use strict'; this.email = element(by.id('Email')); this.next = element(by.id('next')); this.pwd = element(by.id('Passwd')); this.signin = element(by.id('signIn')); this.submitButton = element(by.css('。login-form button [type =submit]')); //this.classitem = element(by.css('hap-class-item')); //this.googlesigninbtn = element(by.css('[ng-click =login_google()]')); // ********************函数******************* this.enterEmail = function(email) {browser.ignoreSynchronization = true; //browser.sleep(2000); this.email.clear(); this.email.sendKeys(电子邮件); this.next.click(); browser.sleep(2000); }; this.enterPassword = function(pwd){browser.ignoreSynchronization = true; this.pwd.clear(); browser.sleep(2000); this.pwd.sendKeys(PWD); this.signin.click(); browser.sleep(2000); };}; module.exports = {log:new loginPage()};



下面是我的退出页面对象

  / *文件名:logoutPage.js * / var logoutPage = function() {'use strict'; this.logoutcaret = element(by.css('[ng-if =api.userNav.items]')); this.logoutbtn = element(by.css('[ng-click =openModal()]')); this.googlelogout = element(by.css('[ng-click =logout()]')); var EC1 = protractor.ExpectedConditions; // ********************函数******************* this.logoutfn = function(){ browser.wait(EC1.visibilityOf(this.logoutcaret),15000); this.logoutcaret.click(); this.logoutbtn.click(); this.googlelogout.click(); };}; module.exports = {log:new logoutPage()};  



下面是我的基页,其中创建了用于每个测试的登录和注销功能

  / *文件名:LoginOut.js * /// var switchwin = require('../ commons / selectwindow.js'); var loginPage = require('../ objects / loginpage.js'),eml ='abc',password = 'pwd'; exports.login = function(){//browser.driver.manage()。deleteAllCookies(); browser.driver.get( https://accounts.google.com/ServiceLogin’); loginPage.log.enterEmail(EML); loginPage.log.enterPassword(密码); browser.driver.get('URL');}; var logoutPage = require('../ objects / logoutpage.js'); exports.logout = function(){logoutPage.log.logoutfn();};  



最后,下面是我的测试,它总是通过,但它只是登录然后注销但不会在'it'块中执行任何操作。

  / *文件名:tests * /'use strict'; describe('我想测试Smartshare',函数() {var loginMod = require('../ commons / loginout.js'); //在每次测试之前登录beforeEach(function(){loginMod.login();}); var loginMod = require('../ commons / loginout.js'); //每次测试后注销afterEach(function(){loginMod.logout();}); var smartshareMod = require('../ objects / smartsharepage.js'); //复制doc测试它('应测试共享文档',function(){exports.copydoc = function(){smartshareMod.log.copyDoc()。然后(function(){console.log('document copied');});}; });});  


我读过类似的问题,但没有帮助
量角器在不运行测试的情况下通过测试
https://github.com/angular/angular-cli/issues/2072

  node.js版本 -  v6.4.0 
量角器版本 - 4.0.11
在MacOS上运行Sierra
webdriver-manager已更新至最新


解决方案

这是因为你不会调用任何函数 it()块内,修复它:

  it('应该测试共享一个文件',function(){
smartshareMod.log.copyDoc()。然后(function(){
console.log('document copied');
});
});

另请注意,每次使用页面对象时都不必需要 - 要求它们在测试规范的顶部一次并重复使用:

 'use strict'; 

var loginMod = require('../ commons / loginout.js');
var smartshareMod = require('../ objects / smartsharepage.js');

描述('我想测试Smartshare',函数(){
beforeEach(function(){
loginMod.login();
});

afterEach(function(){
loginMod.logout();
});

it('应测试共享文档',函数( ){
smartshareMod.log.copyDoc()。then(function(){
console.log('document copied');
});
});
});


I've recently tried to use the Page Object Model with Protractor following this post http://engineering.wingify.com/posts/angularapp-e2e-testing-with-protractor/

However, when I run my tests, my itblocks do not get executed.

Below is my login page object

/*File Name : loginPage.js*/
var loginPage = function () {
    'use strict';
    this.email = element(by.id('Email'));
    this.next = element(by.id('next'));
    this.pwd = element(by.id('Passwd'));
    this.signin = element(by.id('signIn'));
    this.submitButton = element(by.css('.login-form button[type="submit"]'));
    //this.classitem = element(by.css('hap-class-item'));
    //this.googlesigninbtn = element(by.css('[ng-click="login_google()"]'));

    //******************** functions *******************

    this.enterEmail = function (email) {
        browser.ignoreSynchronization = true;
        //browser.sleep(2000);
        this.email.clear();
        this.email.sendKeys(email);
        this.next.click();
        browser.sleep(2000);
    };

    this.enterPassword = function (pwd) {
        browser.ignoreSynchronization = true;
        this.pwd.clear();
        browser.sleep(2000);
        this.pwd.sendKeys(pwd);
        this.signin.click();
        browser.sleep(2000);
    };
};
module.exports = {
    log: new loginPage()
};

Below is my logout page object

/*File Name : logoutPage.js*/
var logoutPage = function () {
    'use strict';
		this.logoutcaret = element(by.css('[ng-if="api.userNav.items"]'));
    	this.logoutbtn = element(by.css('[ng-click="openModal()"]'));
    	this.googlelogout = element(by.css('[ng-click="logout()"]'));
      var EC1 = protractor.ExpectedConditions;
    //******************** functions *******************
    this.logoutfn = function () {
  	  browser.wait(EC1.visibilityOf(this.logoutcaret),15000);
	    this.logoutcaret.click();
    	this.logoutbtn.click();
    	this.googlelogout.click();
    };
};
module.exports = {
    log: new logoutPage()
};

Below is my Base Page that has login and logout functions created to be used in each test

/*File Name : LoginOut.js*/
//var switchwin = require('../commons/selectwindow.js');
var loginPage = require('../objects/loginpage.js'),
    eml = 'abc',
    password = 'pwd';

exports.login = function () {
    //browser.driver.manage().deleteAllCookies();
    browser.driver.get('https://accounts.google.com/ServiceLogin');
    loginPage.log.enterEmail(eml);
    loginPage.log.enterPassword(password);
    browser.driver.get('URL');
};

var logoutPage = require('../objects/logoutpage.js');
exports.logout = function () {
    logoutPage.log.logoutfn();
};

Lastly, below is my test, which always passes but it merely logs in and logs out however does not perform any actions in the 'it' block.

/*File Name : tests*/
'use strict';

describe('I want to test Smartshare', function () {

   var loginMod = require('../commons/loginout.js');
    //login before each test
    beforeEach(function () {
        loginMod.login();
    });
    var loginMod = require('../commons/loginout.js');
    //logout after each test
    afterEach(function () {
        loginMod.logout();
    });

    var smartshareMod = require('../objects/smartsharepage.js');
    //copy doc test
    it('should test sharing a document', function () {
    	exports.copydoc = function () {
    		smartshareMod.log.copyDoc().then(function(){
    			console.log('document copied');
    		});
    	};
    });
});

I have read similar questions but with no help Protractor passes tests without running the tests and https://github.com/angular/angular-cli/issues/2072

    node.js version - v6.4.0 
    protractor version - 4.0.11 
    Running on MacOS Sierra 
    webdriver-manager updated to latest

解决方案

This is because you don't call any functions inside the it() block, fix it:

it('should test sharing a document', function () {
    smartshareMod.log.copyDoc().then(function() {
        console.log('document copied');
    });
});

Also note that you don't have to "require" your page objects every time you use them - require them at the top of your test spec once and reuse:

'use strict';

var loginMod = require('../commons/loginout.js');
var smartshareMod = require('../objects/smartsharepage.js');

describe('I want to test Smartshare', function () {
    beforeEach(function () {
        loginMod.login();
    });

    afterEach(function () {
        loginMod.logout();
    });

    it('should test sharing a document', function () {
        smartshareMod.log.copyDoc().then(function() {
            console.log('document copied');
        });
    });
});

这篇关于量角器通过我的测试而不执行'it'块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆