![](/img/trans.png)
[英]Is it possible to check if a message doesn't contain “ew” it deletes the message?
[英]Protractor: Is it possible to check if an element doesn't contain certain text?
在我正在测试的页面上,用户可以使用一种货币或多种货币(即EUR和USD),这些货币将在页面顶部的同一div中显示。 如果用户有多种货币,则每种货币的选项卡将在页面的下方显示;如果用户只有一种货币,则不会显示任何选项卡(因为用户无需切换选项卡)。
我可以通过检查标题中包含的文本是否与货币选项卡中包含的文本匹配来测试多币种用户。
但是,由于没有出现单一货币的标签,因此我不确定如何测试。
例如,如果我只有'EUR'货币,有没有办法做类似的事情
if element(by.className("currencies"))contains 'EUR'
&& doesn't contain 'USD' && doesn't contain 'GBP'
expect element(by.className("tabs").toDisplay.toBeFalsy()
这是页面对象文件的代码
this.checkCurrency = function(currency) { var checkBalance = element(by.className("balances")); checkBalance.getText().then(function (text) { if (text.indexOf("GBP" && "EUR")>= 0) { expect(element.all(by.linkText("GBP")).isDisplayed()).toBeTruthy(); console.log("EUR GBP buyer"); } else if (text.indexOf("GBP" && "USD")>= 0) { expect(element.all(by.linkText('USD')).isDisplayed()).toBeTruthy(); console.log("USD GBP buyer"); } else { console.log("false"); } }); };
根据您的描述,我不太确定故障在哪里。 通常,您希望将这种逻辑保留在页面对象之外。 您的测试应了解页面应处于什么状态并调用不同的功能。 我知道这并不总是可能的,但是如果可以的话,效果会更好。 这是一些一般情况建议,应有所帮助。
您可以捕获诺言的成功状态和失败状态。 大多数人使用pass函数,但是忘记了fail函数。
promise.then(passFunction, failFunction)
您可以通过几种不同的方式使用它。 如果您意识到量角器中的几乎所有东西都在兑现承诺。 例:
element(by.className("currencies")).getText()
.then(
function(text) {
//check on something
},function(error){
//don't check on something
if(someCondition) {
throw error;
} else {
//the test continues
}
});
您甚至可以做到并期望
expect(element(by.className("currencies")).getText()).not.toContain("EUR")
.then(
function(passed) {
//check on something
},function(failed){
//don't check on something
if(someCondition) {
throw failed;
} else {
//the test continues
}
});
或简单的findElement
element(by.className("currencies"))
.then(
function(element) {
//check on something
},function(error){
//don't check on something
if(someCondition) {
throw failed;
} else {
//the test continues
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.