gpt4 book ai didi

javascript - Protractor 点击功能并不总是有效

转载 作者:行者123 更新时间:2023-12-02 06:52:00 27 4
gpt4 key购买 nike

我是 Protractor 的新手。我已经为 Angular 编写了一个测试,第一个用户登录到应用程序,然后单击特定按钮来计算一个数字。有时有效,有时无效!

这是代码:

describe('Protractor Demo App', function () {

it('should login to app', function () {
browser.get('http://localhost:8080/main');
var userName = element(by.id('username'));
var passWord = element(by.id('pwd'));
var loginBtn = element(by.id('loginBtn'));
userName.sendKeys('user');
passWord.sendKeys('1');
loginBtn.click();
expect(browser.getCurrentUrl()).toEqual('http://localhost:8080/main/#/intro');
});


it('should calculate something', function () {
browser.get('http://localhost:8080/main/#/something');
var next = element(by.css('[ng-click="calculate()"]'));
element(by.model('accountNo')).sendKeys('0293949223008');
next.click();
expect(element(by.binding('result')).getText()).toEqual('55017000000029');
});

it('should show error for invalid input no', function () {
browser.get('http://localhost:8080/main/#/something');
var next = element(by.css('[ng-click="calculate()"]'));
element(by.model('accountNo')).sendKeys('9999456123789');
next.click();
expect(element(by.css('[class="messageObject warning"]')).getText()).toEqual('message for invalid input');
});
});

第一个“it”总是有效,但第二个和第三个有时有效。碰巧只有其中一个没有起作用;

这是错误:

message: Failed: unknown error: Element ... is not clickable at point (1214, 275). Other element would receive the click: ... (Session info: chrome=55.0.2883.87) (Driver info: chromedriver=2.26.436362 (5476ec6bf7ccbada1734a0cdec7d570bb042aa30),platform=Windows NT 10.0.10240 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 78 milliseconds Build info: version: '2.53.1', revision: 'a36b8b1', time: '2016-06-30 17:37:03' System info: host: 'user', ip: 'ip', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_45' Driver info: org.openqa.selenium.chrome.ChromeDriver Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.26.436362 (5476ec6bf7ccbada1734a0cdec7d570bb042aa30), userDataDir='add'}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=55.0.2883.87, platform=WIN8_1, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=}] Session ID: 45d78fbebf15daa1dde971f5f7470551

不知道是什么问题。谁能帮我?提前致谢。

最佳答案

在执行点击操作之前,用 ExpectedConditions.isElementToBeClickable() 方法实现 browser.wait() 。您关注如下:

   var EC = protractor.ExpectedConditions;

it('should show error for invalid input no', function (){
browser.get('http://localhost:8080/main/#/something');
var next = element(by.css('[ng-click="calculate()"]'));
element(by.model('accountNo')).sendKeys('9999456123789');

browser.wait(EC.elementToBeClickable(next ), 10000,'Element not
clickable');
next.click();
expect(element(by.css('[class="messageObject
warning"]')).getText()).toEqual('message for invalid input');
});

关于javascript - Protractor 点击功能并不总是有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41343207/

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