Angularjs 从非角度登录页面进行量角器测试
我正在尝试从我的站点测试基本登录/注销。MyAngular应用程序的入口点来自非angular登录页面(oauth),该页面在验证凭据后为应用程序提供服务。我的测试将在本地运行,但不会在Circle Ci上运行;我的错误是Angularjs 从非角度登录页面进行量角器测试,angularjs,protractor,Angularjs,Protractor,我正在尝试从我的站点测试基本登录/注销。MyAngular应用程序的入口点来自非angular登录页面(oauth),该页面在验证凭据后为应用程序提供服务。我的测试将在本地运行,但不会在Circle Ci上运行;我的错误是 Message: Failed: Error while waiting for Protractor to sync with the page: "angular could not be found on the window" Stack: Error:
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"
以下是我的测试函数:
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
移动到每次之前的和每次之后的:
beforeEach(function () {
browser.ignoreSynchronization = true;
});
afterEach(function () {
browser.ignoreSynchronization = false;
});
帮助我解决:.尝试将忽略同步
移动到之前
和之后
:
beforeEach(function () {
browser.ignoreSynchronization = true;
});
afterEach(function () {
browser.ignoreSynchronization = false;
});
帮助我解决:.用browser.sleep(10000)替换setTimeout调用
setTimeout在超时后执行回调函数,但主“线程”继续其执行流。所以你不是真的在等
此外,您还可以在最后一次注销之前使用browser.waitForAngular()
大概是这样的:
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;
})) 用browser.sleep(10000)替换setTimeout调用
setTimeout在超时后执行回调函数,但主“线程”继续其执行流。所以你不是真的在等
此外,您还可以在最后一次注销之前使用browser.waitForAngular()
大概是这样的:
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;
})) 一个真正的非角度网站可能会有browser.ignoreSynchronization移动到Beforeal并没有问题,但这是一个很好的起点。@alecxe but Beforeach也会影响角度规格(it
),对吗?如果测试套件中有它们中的任何一个(描述
)。@GirishSortur是的,这可能会成为一个问题,让我们看看OP会说什么,谢谢!一个真正的非角度网站可能会有browser.ignoreSynchronization移动到Beforeal并没有问题,但这是一个很好的起点。@alecxe but Beforeach也会影响角度规格(it
),对吗?如果测试套件中有它们中的任何一个(描述
)。@GirishSortur是的,这可能会成为一个问题,让我们看看OP会说什么,谢谢!在测试代码时引入sleep命令不是很糟糕吗?当你在测试周期中复合这些显式睡眠时,你最终会浪费时间,或者,有时,没有足够的等待时间,因为你必须等待,即使你在页面上寻找的内容已经存在,或者睡眠时间不够长,这破坏了你的测试。是的,我完全同意,但是如果这个人使用睡眠呼叫,他应该使用browser.sleep()
,而不是setTimeout
。在测试代码时引入sleep命令不是很糟糕吗?当你在测试周期中复合这些显式睡眠时,你最终会浪费时间,或者,有时,没有足够的等待时间,因为你必须等待,即使你在页面上寻找的内容已经存在,或者睡眠时间不够长,这破坏了你的测试。是的,我完全同意,但是如果这个人使用睡眠呼叫,他应该使用browser.sleep()
,而不是setTimeout
。