【问题标题】:Protractor passes my tests without executing the 'it' blocks量角器通过了我的测试而不执行“it”块
【发布时间】:2016-12-29 22:57:54
【问题描述】:

我最近尝试在这篇文章之后将页面对象模型与 Protractor 一起使用 http://engineering.wingify.com/posts/angularapp-e2e-testing-with-protractor/

但是,当我运行测试时,我的 itblocks 没有被执行。

下面是我的登录页面对象

/*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()
};

下面是我的注销页面对象

/*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()
};

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

/*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();
};

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

/*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');
    		});
    	};
    });
});
我读过类似的问题,但没有帮助 Protractor passes tests without running the testshttps://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

【问题讨论】:

    标签: javascript jasmine protractor pageobjects


    【解决方案1】:

    这是因为您没有在it() 块内调用任何函数,请修复它:

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

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

    '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');
            });
        });
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-11
      相关资源
      最近更新 更多