关于angularjs:来自非angular登录页面的protractor测试

Protractor test from non-angular login page

我正在尝试从我的站点测试基本登录/注销。我的 Angular 应用程序的入口点来自非 Angular 登录页面 (oauth),然后在验证凭据后为应用程序提供服务。我的测试将在本地运行,但不会在 Circle Ci 上运行;我的错误是这样的;

1
2
3
4
Message:
    Failed: Error while waiting for Protractor to sync with the page:"angular could not be found on the window"
  Stack:
Error: Failed: Error while waiting for Protractor to sync with the page:"angular could not be found on the window"

这是我的测试函数:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
    it('Log into Webapp', function() {
     browser.ignoreSynchronization = true;
        browser.manage().timeouts().pageLoadTimeout(40000);
        browser.manage().timeouts().implicitlyWait(25000);

        browser.get('http://localhost:8000/login');

        element(by.id('username')).sendKeys('x..');
        element(by.id('password')).sendKeys('...');
        element(by.name('Login')).click();

        setTimeout(function(){}, 15000);
        element(by.name('save')).click();

        setTimeout(function(){}, 10000);
        //browser.waitForAngular();
        //browser.ignoreSynchronization = false;
        //browser.ignoreSynchronization = false;
        // Angular app should be served, Logout is on this
        browser.ignoreSynchronization = false;

        element(by.name('logoutBtn')).click();

});

尝试将 ignoreSynchronization 移动到 beforeEachafterEach:

1
2
3
4
5
6
7
beforeEach(function () {
    browser.ignoreSynchronization = true;
});

afterEach(function () {
    browser.ignoreSynchronization = false;
});

帮我解决:点击后打开非角页面。


将 setTimeout 调用替换为 browser.sleep(10000);

setTimeout 在超时后执行回调函数,但主"线程"继续其执行流程。所以你并不是真的在等待。

另外,您可以在最后一次 logoutBtn 点击之前使用 browser.waitForAngular()。

类似这样的:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
it('Log into Webapp', function() {
    browser.ignoreSynchronization = true;
    browser.manage().timeouts().pageLoadTimeout(40000);
    browser.manage().timeouts().implicitlyWait(25000);

    browser.get('http://localhost:8000/login');

    element(by.id('username')).sendKeys('x..');
    element(by.id('password')).sendKeys('...');
    element(by.name('Login')).click();

    browser.sleep(15000);
    element(by.name('save')).click();

    browser.sleep(10000);
    browser.waitForAngular();        

    element(by.name('logoutBtn')).click();

    // Angular app should be served, Logout is on this
    browser.ignoreSynchronization = false;

});