我有以下测试,当我使用 firefox 和 chrome 在本地和酱汁(至少大部分时间)上运行它们时,它们运行良好。
ptor = protractor.getInstance();
baseUrl = protractor.getInstance().params.sBaseUrl;
aRequiredTextFieldsKeys = [
'sFirstName',
'sLastName',
'sStreet',
'sZip',
'sCity'
];
describe('form', function ()
{
var sFormUrl = baseUrl + '#/form';
beforeEach(function ()
{
ptor.get(sFormUrl);
});
describe('wholeForm', function ()
{
it('fully filled form => required fields have correct class && submit leads to other route', function ()
{
function checkRequiredClass(el)
{
expect(el.getAttribute('class')).toContain('ng-valid-required');
}
// requried text-fields
for (var i = 0; i < aRequiredTextFieldsKeys.length; i++) {
var el = element(by.model('oFormData.' + aRequiredTextFieldsKeys[i]));
el.sendKeys('a');
checkRequiredClass(el);
}
// email
var elEmail = element(by.model('oFormData.sEmail'));
elEmail.sendKeys('jo@jo.de');
checkRequiredClass(el);
// birthday
var elBirthday = element(by.model('oFormData.oBirthday'));
elBirthday.sendKeys('1.1.1995');
checkRequiredClass(el);
// checkboxes
var elCheck1 = element(by.model('oFormData.bAgb'));
elCheck1.click();
checkRequiredClass(elCheck1);
var elCheck2 = element(by.model('oFormData.bPrivatePolicy'));
elCheck2.click();
checkRequiredClass(elCheck2);
// hack upload bon
ptor.executeScript(function ()
{
var scope = $('#application-form-id').scope();
scope.oFormData.bBonUploaded = true;
});
// submit form
element(by.className('btn-submit')).click();
ptor.getCurrentUrl()
.then(function (url)
{
expect(url).toNotBe(sFormUrl);
});
});
});
但是当我启动 Internet Explorer 或 safari 时,我会遇到各种错误,而手动测试时页面工作正常。对于 IE,我得到:
消息:UnknownError:JavaScript 错误(警告:服务器未提供任何堆栈跟踪信息)命令持续时间或超时:97 毫秒构建信息:版本:'2.30.0',修订:'dc1ef9c',时间:'2013-02-19 00:15:27' 系统信息:os.name:'Windows Server 2008 R2',os.arch:'x86',os.version:'6.1',java.version:'1.6.0_35' 会话 ID:42b30348- 8598-4edb-923e-a7019ced6eb0 驱动程序信息:org.openqa.selenium.ie.InternetExplorerDriver 功能 [{platform=WINDOWS, elementScrollBehavior=0, javascriptEnabled=true, enablePersistentHover=true, ignoreZoomSetting=false, browserName=internet explorer, enableElementCacheCleanup=true , unexpectedAlertBehaviour=dismiss, version=10, cssSelectorsEnabled=true, ignoreProtectedModeSettings=false,requireWindowFocus=false,allowAsynchronousJavaScript=false,handlesAlerts=true,initialBrowserUrl=,nativeEvents=true,takeScreenshot=true}]
错误:等待量角器与页面同步时出错:{"stack":"TypeError: Unable to get property 'get' of undefined or null reference\n at Anonymous function (Unknown script code:25:5)\n at匿名函数(未知脚本代码:21:14)\n 在匿名函数(未知脚本代码:21:2)","description":"无法获取未定义或空引用的属性 'get'","number": -2146823281}
对于 Safari:
UnknownError:检测到页面卸载事件;脚本执行不适用于页面加载。(警告:服务器未提供任何堆栈跟踪信息)命令持续时间或超时:384 毫秒构建信息:版本:'2.33.0',修订:'4e90c97',时间:'2013-05-22 15:32:38'系统信息:os.name:'Windows Server 2008 R2',os.arch:'x86',os.version:'6.1',java.version:'1.6.0_35' 会话 ID:空驱动程序信息:org.openqa。 selenium.safari.SafariDriver 功能 [{platform=WINDOWS, javascriptEnabled=true, cssSelectorsEnabled=true, secureSsl=true, browserName=safari, takeScreenshot=true, version=5.1.7}]
我对原因感到困惑。我尝试了更简单的测试,结果相同,我尝试了本地和远程 url,我尝试了各种延迟,比如waitForAngular
,wait
和ptor ignoreAsynch = true
. 它们都不会导致预期的结果。有什么建议么?
我的量角器配置文件:
// A reference configuration file.
exports.config = {
seleniumServerJar: null,
seleniumPort: null,
chromeOnly: false,
// Additional command line options to pass to selenium. For example,
// if you need to change the browser timeout, use
// seleniumArgs: ['-browserTimeout=60'],
seleniumArgs: [],
sauceUser: 'saucesuer',
sauceKey: 'key',
allScriptsTimeout: 120000,
specs: [
'test/e2e/**/*.js',
],
// https://code.google.com/p/selenium/wiki/DesiredCapabilities
// https://code.google.com/p/selenium/source/browse/javascript/webdriver/capabilities.js
capabilities: {
'browserName': 'phantomjs',
'phantomjs.binary.path':'node_modules/phantomjs/bin/phantomjs'
},
// Selector for the element housing the angular app - this defaults to
// body, but is necessary if ng-app is on a descendant of <body>
rootElement: 'body',
onPrepare: function ()
{
// driver.manage().timeouts().setScriptTimeout(60000);
},
params: {
sBaseUrl: 'https://dev.com/'
},
baseUrl: 'http://localhost:8000',
framework: 'jasmine',
// ----- Options to be passed to minijasminenode -----
//
// See the full list at https://github.com/juliemr/minijasminenode
jasmineNodeOpts: {
// onComplete will be called just before the driver quits.
onComplete: null,
// If true, display spec names.
isVerbose: true,
// If true, print colors to the terminal.
showColors: true,
// If true, include stack traces in failures.
includeStackTrace: true,
// Default time to wait in ms before a test fails.
defaultTimeoutInterval: 120000
}
};
虽然这似乎无关紧要,但我使用 grunt-protractor runner 来顺序运行多个实例。
chrome: {
options: {
args: {
browser: 'chrome',
"idle-timeout": 120
}
}
},
firefox: {
options: {
args: {
browser: 'firefox'
}
}
},
ie9: {
options: {
args: {
browser: 'internet explorer',
version: '9',
"idle-timeout": 120
}
}
},
ie10: {
options: {
args: {
browser: 'internet explorer',
version: '10'
}
}
},
safari7: {
options: {
args: {
browser: 'safari',
version: '7'
}
}
},
safari6: {
options: {
args: {
browser: 'safari',
version: '6'
}
}
},
safari5: {
options: {
args: {
browser: 'safari',
version: '5'
}
}
}
}
grunt.registerTask('e2eall', [
'protractor:ie9',
'protractor:ie10',
'protractor:safari5',
'protractor:safari6',
'protractor:safari7',
'protractor:firefox',
'protractor:chrome'
]);