2016-06-13 118 views
1

我有一个方案,我搜索一个文本字符串,它可能是返回结果中任何字段的一部分,它可能在标题中,或者汇总或描述返回的多个结果。我想写一个可以匹配这三个字段的测试,如果其中任何一个是真的,那么我的测试应该通过。如何验证是否有任何一个期望是真实的多个期望条件

我怎样才能把多个期望条件与OR条件。

+0

检查也是在这里我的答案 - http://stackoverflow.com/questions/37800341/assert-an-array-reduces-to-true/37808169#37808169 – Xotabu4

回答

2

可以与protractor.promise.all()解决它:

var title = element(by.id("title")), 
    summary = element(by.id("summary")), 
    description = element(by.id("description")); 

protractor.promise.all([ 
    title.isPresent(), 
    summary.isPresent(), 
    description.isPresent() 
]).then(function (arrExists) { 
    expect(arrExists.reduce(function(a,b) { return a || b; })).toBe(true); 
}); 

此测试会通过,如果3个字段的的至少一个是本


如果你问具体为约等待的元素之一出现,你可以使用protractor.ExpectedConditions.or()

var title = element(by.id("title")), 
    summary = element(by.id("summary")), 
    description = element(by.id("description")); 

browser.wait(EC.or(
    EC.presenceOf(title), 
    EC.presenceOf(summary), 
    EC.presenceOf(description)), 5000); 
+0

我不想检查元素的存在,我想检查搜索到的文本是否与返回的结果匹配,并且搜索文本可能位于结果的这三个字段(标题,摘要,描述)中的任何一个中。我怎样才能做到这一点 ? – ssharma

1

在Java中,我们可以使用或像下面

 String expected="cool"; //this is my expected value 

     String actual1="cool"; //get title from driver 
     String actual2="xyz"; //get summary from driver 
     String actual3="abc"; //get required text from driver 

    Assert.assertTrue((expected.equals(actual1)) | (expected.equals(actual2)) | (expected.equals(actual3))); 

如果您正在查找标题或摘要的句子中的特定单词,下面的方法将有所帮助。

 String actual1="its very cool"; //get title from driver 
     String actual2="xyz"; //get summary from driver 
     String actual3="abcd"; //get required text from driver 

    //here i am checking for cool  
    Assert.assertTrue((actual1.matches(".*cool.*")) | (actual2.matches(".*cool.*")) | (actual3.matches(".*cool.*"))); 
+0

Thansk为您的回复@murali,但我正在寻找在量角器的决议。 – ssharma

相关问题