我安装了node.js 和 Protractor 。我有使用 selenium-webdriver 的经验,但是 Protractor 让我发疯!我对 javascript 也不太熟悉。
这就是我的代码:
describe('My app', function() {
var result = element(by.id('result-name'));
var enterBtn = element(by.id('enter'));
var clearFieldBtn = element(by.id('clear-field');
it('should bring up components on load', function() {
browser.get(`http://localhost:${process.env.PORT}`);
browser.wait(until.titleContains('Sample App'), 500);
browser.wait(until.presenceOf(browser.element(by.id('my-test-app'))), 500);
expect(enterBtn).isPresent;
});
it('result should equal username', function () {
browser.get(`http://localhost:${process.env.PORT}`);
expect(clearFieldBtn).isPresent;
expect(result.getText()).toEqual('John Smith'); //both tests pass without this line of code
});
});
最后一行“expect(result.getText()).toEqual('John Smith');”给我一个错误。我得到:
expect(...).toEqual is not a function
任何帮助将不胜感激。我花了几个小时试图找到解决方案并尝试不同的事情。
我还想实现 isPresent 函数,它是如何在 api 文档中完成的,如下所示:expect($('.item').isPresent()).toBeTruthy();
我尝试这样做:
expect(clearFieldBtn).isPresent().toBeTruthy();
但我知道 isPresent 不是一个函数...
最佳答案
这条线之上的预期似乎很差。应该是这样的:
expect(clearFieldBtn.isPresent()).toBeTruthy();
不确定这是否会导致下面一行出现奇怪的错误...只是想我会把它扔在那里。所有 Protractor API 都需要在 Expect 内调用,因为 isPresent
不是 expect
关于javascript - getText 不是函数错误 - Protractor (javascript),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43659839/