我们对Protractor进行了一系列相当大的端到端测试.我们遵循Page Object模式,这有助于我们保持测试的清洁和模块化.我们还有一套辅助功能,可以帮助我们遵循DRY原则.
问题:
单个规范可能需要多个页面对象和辅助模块.例如:
"use strict";
var helpers = require("./../../helpers/helpers.js");
var localStoragePage = require("./../../helpers/localStorage.js");
var sessionStoragePage = require("./../../helpers/sessionStorage.js");
var loginPage = require("./../../po/login.po.js");
var headerPage = require("./../../po/header.po.js");
var queuePage = require("./../../po/queue.po.js");
describe("Login functionality", function () {
beforeEach(function () {
browser.get("/#login");
localStoragePage.clear();
});
// ...
});
Run Code Online (Sandbox Code Playgroud)
您可以看到我们在每个require语句中都有遍历目录:./../..
.这是因为我们有一个specs
目录,我们将规范和多个目录保存在由测试中的应用程序功能分组.
问题:
在Protractor中处理相对路径问题的规范方法是什么?
换句话说,我们想避免遍历树,进入导入模块.从基础应用程序目录下来会更加清晰.
尝试和想法:
有一篇关于解决这个问题的好文章:Node.js的本地require()路径更好,但我不确定在使用Protractor开发测试时哪一个选项是推荐的.
我们也尝试使用require.main
构造路径,但它指向node_modules/protractor
目录而不是我们的应用程序目录.
我是量角器的新手,我正在尝试实施e2e测试.我不知道这是否是正确的方法,但是...我要测试的页面不是基于完整的角度页面,所以......我遇到了一些麻烦.
根据我的第一个规范,我有:
describe('should open contact page', function() {
var ptor = protractor.getInstance();
beforeEach(function(){
var Login = require('./util/Login');
new Login(ptor);
});
Run Code Online (Sandbox Code Playgroud)
我已创建此Login类,但登录后我想打开联系页面,但量角器会在页面完全加载之前立即尝试查找元素.
我试过用:
browser.driver.wait(function() {
expect(browser.findElement(by.xpath("//a[@href='#/contacts']")).isDisplayed());
ptor.findElement(by.xpath("//a[@href='#/contacts']")).click();
});
Run Code Online (Sandbox Code Playgroud)
但它不起作用......它总是试图在页面加载之前找到元素.我也试过这个:
browser.driver.wait(function() {
expect(ptor.isElementPresent(by.xpath("//a[@href='#/contacts']")));
ptor.findElement(by.xpath("//a[@href='#/contacts']")).click();
});
Run Code Online (Sandbox Code Playgroud)
我能够使用browser.sleep();
但我不认为这是一个不错的选择.任何的想法?在我的登录课上,我有:
ptor.ignoreSynchronization = true;
Run Code Online (Sandbox Code Playgroud)
@href='#/contacts
在量角器尝试点击它之前,我该如何等待?
javascript automated-tests angularjs selenium-webdriver protractor
量角器什么是选择子元素的最佳方式?假设我们有以下布局......
<div id='parent_1'>
<div class='red'>Red</div>
<div class='blue'>Blue</div>
</div>
<div id='parent_2'>
<div class='red'>Red</div>
<div class='blue'>Blue</div>
</div>
Run Code Online (Sandbox Code Playgroud)
使用jQuery,我们会做这样的事情.
var p1 = $('#parent_1');
var p1_red = $('.red', p1); //or p1.find('.red');
var p1_blue = $('.blue', p1); //or p1.find('.blue');
Run Code Online (Sandbox Code Playgroud)
但是使用Protractor,首先获得父元素是否有意义?因为这样做var p1 = element('#parent_1');
实际上不会检索/搜索对象,直到getText()
调用它为止.
这样做..
场景1
expect(p1.element('.red')).toBe('red');
expect(p1.element('.blue')).toBe('blue');
Run Code Online (Sandbox Code Playgroud)
要么
情景2
expect(element('#parent_1').element('.red')).toBe('red');
expect(element('#parent_1').element('.blue')).toBe('blue');
Run Code Online (Sandbox Code Playgroud)
要么
场景3
expect(element('#parent_1 > .red')).toBe('red');
expect(element('#parent_1 > .blue')).toBe('blue');
Run Code Online (Sandbox Code Playgroud)
一种方法相对于另一种方法有什么好处吗?
这就是我正在做的事情,但我不知道将父母与cssSelector分开是否有任何好处:
function getChild(cssSelector, parentElement){
return parentElement.$(cssSelector);
}
var parent = $('#parent_1');
var child_red = getChild('.red', parent);
var child_blue = getChild('.blue', parent); …
Run Code Online (Sandbox Code Playgroud) 尝试执行'npm install'命令时,我收到如下所示的错误.
错误:无法建立隧道套接字,因为= connect ECONNREFUSED 10.232.207.137:8080
我错过了什么?
我使用Protular与Angular 1.x. 我想逐步迁移到Angular 2.0,但我没有在文档中看到Protractor .
自Angular 2以来,量角器已被丢弃吗?我应该在不使用Protractor的情况下编写测试,而不是使用Jasmine(或其他)吗?
我正在Protractor中为Angular应用程序编写测试.我想填写一份登录表格并提交.
我怎样才能做到这一点?我已经做到这一点,但我不知道如何设置电子邮件和密码字段的值.
describe('The dashboard', function() {
ptor = protractor.getInstance();
beforeEach(function() {
ptor.get('#/dashboard');
var email = ptor.findElement(protractor.By.model('email'));
var password = ptor.findElement(protractor.By.model('password'));
var submit = ptor.findElement(protractor.By.tagName('button'));
// Fill out the form?
submit.click();
});
it('has a heading', function() {
heading = ptor.findElement(protractor.By.tagName('h1'));
expect(heading.getText()).toEqual('My Dashboard');
});
});
Run Code Online (Sandbox Code Playgroud) 我正在使用Protractor编写自动化测试脚本,现在我需要使用Jenkins为此设置CI.
它需要执行的任务是:
任何人都可以帮助这方面吗?
我按照本教程安装了量角器,当我使用webdriver-manager更新时,它说:
selenium standalone is up to date.
chromedriver is up to date.
Run Code Online (Sandbox Code Playgroud)
当你尝试进行量角器测试时,它说:
C:\Users\****\AppData\Roaming\npm\node_modules\protractor\lib\driverProviders\local.dp.js:42
throw new Error('Could not find chromedriver at ' +
^
Error: Could not find chromedriver at C:\Users\****\AppData\Roaming\npm\node_modules\protractor\selenium\chromedriver.exe
at LocalDriverProvider.addDefaultBinaryLocs_ (C:\Users\****\AppData\Roaming\npm\node_modules\protractor\lib\driverProviders\local.dp.js:42:15)
at LocalDriverProvider.setupEnv (C:\Users\****\AppData\Roaming\npm\node_modules\protractor\lib\driverProviders\local.dp.js:59:8)
at Runner.run (C:\Users\****\AppData\Roaming\npm\node_modules\protractor\lib\runner.js:308:31)
at process.<anonymous> (C:\Users\****\AppData\Roaming\npm\node_modules\protractor\lib\runFromLauncher.js:32:14)
at process.EventEmitter.emit (events.js:98:17)
at handleMessage (child_process.js:318:10)
at Pipe.channel.onread (child_process.js:345:11)
[launcher] Runner Process Exited With Error Code: 8
Run Code Online (Sandbox Code Playgroud)
我检查了local.dp.js并看到它试图从.. \node_modules\protractor\selenium\chromedriver加载chromedriver但是只有一个名为chromedriver_2.9的空zip文件.
所以我手动下载了chromedriver并将其复制到这个位置,产生了一个新的错误:
C:\Users\****\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:1549
throw error;
^
Error: Server exited with 1 …
Run Code Online (Sandbox Code Playgroud) 在量角器端到端测试中,我想检查一个元素是否存在使用元素(by.css(...)),我的代码:
var myElement = element(by.css('.elementClass'));
expect(myElement).toBeUndefined;
Run Code Online (Sandbox Code Playgroud)
该测试失败,它说:
Expected { locator_ : { using : 'css selector', value : 'div[ng-switch-
when="resultNav"]' }, parentElementFinder_ : null, opt_actionResult_ :
undefined, opt_index_ : undefined, click : Function, sendKeys : Function,
getTagName : Function, getCssValue : Function, getAttribute : Function, getText
: Function, getSize : Function, getLocation : Function, isEnabled : Function,
isSelected : Function, submit : Function, clear : Function, isDisplayed :
Function, getOuterHtml : Function, getInnerHtml : Function, toWireValue :
Function } to …
Run Code Online (Sandbox Code Playgroud) 如何在angularjs量角器jasmine测试中查看console.log输出?截至目前,浏览器自动关闭太快.
更多信息 - 我正在使用angularjs教程,第8步.我正在尝试将e2e测试更改为量角器.我正在使用的量角器配置文件基于%appdata%\npm \node_modules\protractor\referenceConf.js.在配置文件引用的spec js文件中,我有console.log的实例.但是,在执行量角器e2e测试期间,网站以chrome格式打开,我看到事情发生在浏览器中,然后浏览器关闭,然后我才能检查任何console.log输出.我想我需要以某种方式保持镀铬.怎么样?
protractor ×10
angularjs ×6
javascript ×4
selenium ×2
testing ×2
angular ×1
chaining ×1
e2e-testing ×1
element ×1
jasmine ×1
jenkins ×1
migration ×1
npm ×1
parent-child ×1
windows ×1