测试代码:
describe('mysite',function(){
var init_url = 'http://localhost/mySite/#/home';
beforeEach(function(){
// driver = new webdriver.Builder().
// withCapabilities(webdriver.Capabilities.phantomjs()).build();
})
it('should click on toolbox and do stuff', function(){
browser.get(init_url);
browser.waitForAngular();
browser.getCurrentUrl().then(function(url){
console.log('current_url', url);
expect(init_url).toEqual(init_url);
})
expect(true).toBe(true);
browser.sleep(2000);
})
Run Code Online (Sandbox Code Playgroud)
结果第一次运行,
Using the selenium server at http://localhost:9515
data Zoom Pad
class active
mysite
should click on toolbox and do stuff
Finished in 3.94 seconds
1 test, 4 assertions, 0 failures
Run Code Online (Sandbox Code Playgroud)
第二次运行,没有任何中断,只需向上箭头并输入:
Stacktrace:
Error: Error while running testForAngular: Error Message => 'Detected a pag
e unload event; asynchronous …Run Code Online (Sandbox Code Playgroud) 我正在尝试在表格中测试一个打开新窗口的链接.我想测试新窗口的url.
到目前为止我所拥有的是:
it('Should verify new window url', function () {
page.list.get(0).click().then(function () {
browser.getAllWindowHandles().then(function (handles) {
newWindowHandle = handles[1];
browser.switchTo().window(newWindowHandle).then(function () {
expect(browser.getCurrentUrl()).toMatch(/\/url/);
});
});
});
});
Run Code Online (Sandbox Code Playgroud)
错误:等待Protractor与页面同步时出错:{}
如果我删除了期望的作品....我对承诺感到困惑,有人可以指导我正确的方向吗?
我是e2e测试中的床主,有问题.当我登录时 - 我从login.php重定向到index.php页面.但是我的测试失败并出现以下错误:
..A Jasmine spec timed out. Resetting the WebDriver Control Flow.
F
Failures:
1) Login Page should login and redirect to overview page with CR Operators rights
Message:
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
Stack:
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
3 specs, 1 failure
Run Code Online (Sandbox Code Playgroud)
我的代码:
it('should login and redirect to overview page with CR Operators rights', function(sync) {
element(by.model('username')).clear().sendKeys('testuser');
element(by.model('password')).clear().sendKeys('test');
element(by.css('[type="submit"]')).click();
expect(browser.getLocationAbsUrl()).toMatch('/overview');
}); …Run Code Online (Sandbox Code Playgroud) 我用Protractor测试我的角度应用程序.一旦用户登录到我的应用程序,我设置$ timeout以在一小时内完成某项工作(因此,如果用户在13:00登录,则$ timeout将在14:00运行).我一直遇到这些失败:
"Timed out waiting for Protractor to synchronize with the page after 20 seconds. Please see https://github.com/angular/protractor/blob/master/docs/faq.md. The following tasks were pending: - $timeout: function onTimeoutDone(){....."
Run Code Online (Sandbox Code Playgroud)
我已经阅读了这个超时页面:https://github.com/angular/protractor/blob/master/docs/timeouts.md 所以我理解量角器等待页面完全加载,这意味着他正在等待$ timeout完成...
如何让Protractor不等待$ timeout?我不想用:
browser.ignoreSynchronization = true;
Run Code Online (Sandbox Code Playgroud)
因为那时我的测试会因其他原因而失败(其他角度组件仍然需要加载的时间......)
我试图用量角器测试Angular单页应用程序.我需要先运行登录脚本.只有这样我才能转移到其他路线,因为localStorage路线更换时会检查令牌.
这种测试方法是否正确?在这种情况下,我需要先运行登录脚本.量角器是否允许控制spec文件顺序.
或者我应该通过硬编码令牌来独立运行每个脚本localStorage(我应该在每次测试之前独立登录api调用).
我的登录脚本包含以下内容
it('Login with wrong email', function() {
})
it('Login with correct email', function() {
})
Run Code Online (Sandbox Code Playgroud)
因此,在运行之后,Login with correct mail我将获得将存储在localStorage中的accessToken,并且我可以继续测试其他路由.这是正确的方法吗?如果不是如何通过端到端登录测试单个应用程序.
在量角器样式指南中,它被称为
使您的测试彼此独立
因此,我应该beforeAll, beforeEach在每次测试之前使用获取访问令牌并存储在localStorage中.在那种情况下,请解释我如何做到这一点.
任何帮助是极大的赞赏.
谢谢.
angularjs angularjs-e2e protractor e2e-testing gulp-protractor
在Jasmine网站上,我看到我们可以按照xdescribe或按个别规格禁用套件xit.有没有办法只禁用期望(如xexpect)?
我问这个的原因是因为我正在用Protractor编写e2e测试,在我们的持续集成中,我们还没有(如果有的话)可以访问数据库,虽然在本地我们可以运行真正的端到端测试例如,到数据库.
我想将个别期望标记为可选,具体取决于配置或环境变量.做一次切换,然后在expect周围创建一个包装器会很好,只有当我们在本地运行测试(访问数据库)时才会失败.
例如,我可以创建一个新的规范系列:
if (process.env.DB_AVAILABLE) {
dbit = it;
} else {
dbit = xit;
}
Run Code Online (Sandbox Code Playgroud)
并编写依赖于数据库连接的规范,如下所示:
dbit('creates new user', function () {});
Run Code Online (Sandbox Code Playgroud)
有没有办法对expect(例如dbexpect)做同样的事情?
如果我的方法存在根本性的问题,请不要阻止它让我知道.
几天前,当我开始遇到时,我的量角器一直在运行:
Using the selenium server at http://localhost:4444/wd/hub
**** UNCAUGHT EXCEPTION ****
Error: connect ECONNREFUSED
at exports._errnoException (util.js:682:11)
at Object.afterConnect [as oncomplete] (net.js:947:19)
****************************
**** UNCAUGHT EXCEPTION ****
Error: socket hang up
at createHangUpError (_http_client.js:182:15)
at Socket.socketCloseListener (_http_client.js:214:23)
at Socket.EventEmitter.emit (events.js:120:20)
at TCP.close (net.js:459:12)
****************************
Run Code Online (Sandbox Code Playgroud)
使用我的自定义回调方法进一步挖掘e.message打印:
Error:: webdriver is not defined
/home/workspace/desktop/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1702
throw error;
^
ReferenceError: webdriver is not defined
Run Code Online (Sandbox Code Playgroud)
我尝试使用npm install selenium-webdriver安装selenium web驱动程序,但这没有帮助,也试过npm install for protractor但似乎没有什么工作在这里
在这方面的任何帮助都非常感谢.
-Vaibhav
我正在尝试确保在单击某个跨度时页面滚动到元素.所以我需要检查元素的y位置.有人可以解释我如何获得元素的位置吗?
element.all(by.css('[scroll-to="section-executive-summary-anchor"]'))
.then(function (elem) {
elem[0].click().then(function () {
element(by.id('section-executive-summary-anchor'))
.then(function (el) {
// I need "el.position" or something along those lines
});
});
});
Run Code Online (Sandbox Code Playgroud) 我们正在使用量角器测试我们正在构建的前端角度应用程序.
目前我们browser.get()用来指定我们希望再次测试的环境(localhost:9000,staging,UAT)但是我想参数化这个,这样当我们运行我们的测试时,grunt test:e2e我们可以指定一个参数来改变browser.get()指定的环境.
像是能够调用grunt test:e2e NODE_ENV=uat针对指定环境进行测试的东西.
任何人都有任何洞察力如何做到这一点?
angularjs-e2e ×10
protractor ×9
angularjs ×7
javascript ×4
e2e-testing ×2
node.js ×2
database ×1
jasmine ×1
jenkins ×1
karma-runner ×1
phantomjs ×1
selenium ×1