{ beforeEach((-6ren">
gpt4 book ai didi

javascript - 简单测试但定位器无效 :-(

转载 作者:数据小太阳 更新时间:2023-10-29 05:45:08 29 4
gpt4 key购买 nike

我有这个测试:

// import {by, element, browser} from "protractor";
describe('intro', () => {
beforeEach(() => {
browser.get('');
});

it('should have multiple pages', () => {
let buttonOnward = element(by.linkText('Continue'));
expect(element.all(buttonOnward).count()).toBe(1);
});
});

得到这个结果。

1) intro should have multiple pages
Message:
Failed: Invalid locator
Stack:
TypeError: Invalid locator
at Object.check [as checkedLocator] (C:\Users\Patrick\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\by.js:267:9)
at WebDriver.findElements (C:\Users\Patrick\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver.js:919:18)
at C:\Users\Patrick\AppData\Roaming\npm\node_modules\protractor\built\element.js:161:44
at ManagedPromise.invokeCallback_ (C:\Users\Patrick\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:1379:14)
at TaskQueue.execute_ (C:\Users\Patrick\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2913:14)
at TaskQueue.executeNext_ (C:\Users\Patrick\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2896:21)
at asyncRun (C:\Users\Patrick\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2775:27)
at C:\Users\Patrick\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:639:7
at process._tickCallback (internal/process/next_tick.js:103:7)
From: Task: Run it("should have multiple pages") in control flow
at Object.<anonymous> (C:\Users\Patrick\AppData\Roaming\npm\node_modules\protractor\node_modules\jasminewd2\index.js:79:14)
at C:\Users\Patrick\AppData\Roaming\npm\node_modules\protractor\node_modules\jasminewd2\index.js:16:5
at ManagedPromise.invokeCallback_ (C:\Users\Patrick\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:1379:14)
at TaskQueue.execute_ (C:\Users\Patrick\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2913:14)
at TaskQueue.executeNext_ (C:\Users\Patrick\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2896:21)
at asyncRun (C:\Users\Patrick\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2775:27)
From asynchronous test:
Error
at Suite.describe (C:\xampp\htdocs\test\intro_spec.ts:11:3)
at Object.<anonymous> (C:\xampp\htdocs\test\intro_spec.ts:2:1)
at Module._compile (module.js:556:32)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)

1 spec, 1 failure

我也不知道为什么。它真的很简单。我下载了 Jasmine 的类型并检查了这个文件 C:\Users\Patrick\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\by.js

为其定义了一个函数:

The defined function in by.js

并且文档说该函数也存在。

http://www.protractortest.org/#/api?view=ProtractorBy.prototype.buttonText

$ protractor --version
Version 4.0.9
$ npm -v
3.10.8
$ node -v
v6.7.0

提前感谢您的想法!

最佳答案

进一步扩展@Gunderson 的回答。主要问题是您使用的是 ElementFinder(element() 调用的结果)而不是 by 定位器。查看 buttonOnward 是如何定义的:

let buttonOnward = element(by.linkText('Continue'));

现在,您正在使用 buttonOnward,它现在是 ElementFinder 代替定位器:

expect(element.all(buttonOnward).count()).toBe(1);

可以理解,这会导致“无效定位器”错误。


您的意思是改用“by”定位符:

expect(element.all(by.linkText('Continue')).count()).toBe(1);

关于javascript - 简单测试但定位器无效 :-(,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39809915/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com