量angular器:text.indexOf(…).isDisplayed不是一个函数
我知道这已经被问了几次,即使我已经看过这些问题,我不知道如何解决这个问题。
我正在检查文本“EUR”是否包含在一个名为“货币”的div中。 以前这个工作对我来说很好,但是我已经开始使用lint了,而且我也遇到了很多这样的错误。
这是我得到的错误Failed: text.indexOf(...).isDisplayed is not a function
这是我的代码
checkBuyerCurrency (text, buyerCurrency) { let currencyPromise = new Promise(function (resolve, reject) { const commonUtils = new CommonUtils(); var EC = protractor.ExpectedConditions; browser.wait(EC.visibilityOf(element(by.className("currency")), 4000)); var checkCurrency = element(by.className("balances")); checkCurrency.getText().then(function (text) { expect (text.indexOf("EUR").isDisplayed()).toBe(true); console.log("EUR only buyer"); }); }); }
我是否需要将text
variables或将其转换为string? 由于我使用Expect
语句的方式,我不完全确定如何做到这一点
谢谢你的帮助
“isDisplayed()”是Protractor API中的有效函数,但其工作性质就像应用在web元素上来检查元素是否显示在UI上。
但是 ,您将其应用于数字types的文本,这不是预期的isDisplayed()的用法。 如果你的要求是失败的文本是不存在做以下。
checkCurrency.getText().then(function (text) { expect (text.indexOf("EUR")).toBeGreaterTha(-1); });
要么
checkCurrency.getText().then(function (text) { if(text.indexOf("EUR")>-1){ //do what do you want }else{ expect (false).toBe(true);//it will make test case fail is EUR is not //present } });