2016-06-13 6 views
1

텍스트 문자열을 검색하는 시나리오가 있는데 반환 된 결과의 필드 중 일부일 수 있습니다. 제목에있을 수도 있고 반환 된 여러 결과 요약 또는 설명 이 3 개의 필드와 일치 할 수있는 테스트를 작성하고이 중 하나가 사실이라면 테스트가 통과해야합니다.여러 예상 조건 중 하나라도 예상 결과가 true인지 확인하는 방법

OR 조건과 함께 여러 기대 조건을 적용하려면 어떻게해야합니까?

+0

확인도 여기에 내 대답 - http://stackoverflow.com/questions/37800341/assert-an-array-reduces-to-true/37808169#37808169 – Xotabu4

답변

2

당신은 protractor.promise.all() 그것을 해결할 수 : 3 개 필드의 적어도 하나는있는 경우

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); 
}); 

이 테스트는 통과 할 것입니다.

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

자바에서 우리가 사용할 수 있습니다 또는 같은

아래 : 특별히에 대한 표시하는 요소 중 하나 대기 요청하는 경우


, 당신은이 protractor.ExpectedConditions.or() 사용할 수 있습니다

 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

관련 문제