我一直在寻找互联网,但似乎没有任何可靠的资源或示例用量角器JS测试非角度网站。
目前,我的conf文件看起来像这样
exports.config = {
seleniumServerJar: 'webdriver/selenium-server-standalone-2.48.2.jar',
specs: [
'wikipedia-test-spec.js'
],
chromeDriver : 'webdriver/chromedriver.exe',
multiCapabilities: [
{
'browserName': 'chrome'
}
],
};
我的wikipedia-test-spec.js看起来像这样
describe("Tests a wikipedia page", function(){
it('Should check if table exists', function(){
browser.get('https://en.wikipedia.org/wiki/List_of_countries_and_dependencies_by_population');
var table = browser.driver.findElement(by.name('table'));
expect(table.isPresent()).toBeTruthy();
});
});
当我运行protractor conf.js
时,我收到类型错误undefined is not a function
并且我的规范失败了。
更新:
错误的整个堆栈跟踪
Stacktrace:
TypeError: undefined is not a function
at [object Object].<anonymous> (C:\nodejs\CGAngularTest\wikipedia-test-spec.js:5:26)
at C:\Users\jayarajp\AppData\Roaming\npm\node_modules\protractor\node_modules\jasminewd\index.js:94:14
at goog.async.run.processWorkQueue (C:\Users\jayarajp\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\async\run.js:130:15)
From: Task: Asynchronous test function: it()
at [object Object].<anonymous> (C:\Users\jayarajp\AppData\Roaming\npm\node_modules\protractor\node_modules\jasminewd\index.js:93:33)
at [object Object].<anonymous> (C:\Users\jayarajp\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\async-callback.js:45:37)
at [object Object].jasmine.Block.execute (C:\Users\jayarajp\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:1174:17)
at [object Object].jasmine.Queue.next_ (C:\Users\jayarajp\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:2209:31)
at [object Object]._onTimeout (C:\Users\jayarajp\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:2199:18)
Error
at [object Object].<anonymous> (C:\nodejs\CGAngularTest\wikipedia-test-spec.js:2:3)
at [object Object].jasmine.Env.describe_ (C:\Users\jayarajp\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:913:21)
at [object Object].jasmine.Env.describe (C:\Users\jayarajp\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:898:15)
at describe (C:\Users\jayarajp\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:658:27)
at Object.<anonymous> (C:\nodejs\CGAngularTest\wikipedia-test-spec.js:1:63)
答案 0 :(得分:4)
ElementFinder
实例上提供了{p> isPresent()
function,这是element()
调用的结果。您可能需要在此使用driver.isElementPresent()
:
var table = browser.driver.findElement(by.name('table'));
expect(table.isPresent()).toBeTruthy();
使用:
var table = browser.driver.findElement(by.name('table'));
expect(browser.driver.isElementPresent(table)).toBeTruthy();
或者,您也可以尝试element()
:
var table = element(by.name('table'));
expect(table.isPresent()).toBeTruthy();
请注意,您还需要关闭AngularJS的同步:
browser.ignoreSynchronization = true;
另见: