2017-05-23 6 views
0

페이지 객체 패턴을 구현하는 Spock, Groovy 및 Geb에서 UI 기능 테스트를 작성하고 있습니다. 이벤트 내 흐름 중에 결과를 얻을 현재 페이지에서 멀리 이동 메신저 결과로, 나는 내 테스트에서 페이지 개체를 전환하지만 그렇게 성공적으로 아래테스트에서 페이지 객체 사용 전환 - Geb Groovy Spock

테스트 케이스 할 수 있었다를 havent해야합니다

def "Navigate to Second Page"() { 
    when: "I navigate to second page" 

    redirctButton.click() 

    then: "Second Page Url should show" 
    browser.getCurrentUrl() == secondpageUrl 
} 

def "Use method form second page"() { 
    when: "Im on second page" 
    SecondPage.performSearch("search") 

    then: "result should show" 
    SecondPage.resultBox == "" 
} 

답변

0

페이지 개체에 at-checking을 추가 한 다음 at 메서드를 사용하여 예상 한 페이지에 있는지 확인하고 browser.getCurrentUrl() == secondpageUrl을 쓸모 없게 만들 수 있습니다. at -check의 또 다른 효과는 현재 페이지를 변경하고 강력하게 형식화 된 액세스를 위해 페이지 객체를 반환한다는 것입니다. 강하게 입력 된 액세스에 신경 쓰지 않는다면 두 번째 테스트에서 expect 블록을 제거 할 수 있습니다. 입력 된 페이지 객체에 액세스 할 수있는 유일한 공간입니다.


@Stepwise 
class PageTest extends GebReportingSpec { 

def "Navigate to Second Page"() { 
    when: "I navigate to second page" 
    redirctButton.click() 

    then: "Second Page Url should show" 
    at SecondPage 
} 

def "Use method form second page"() { 
    expect: 
    def secondPage = at SecondPage 

    when: "Im on second page" 
    secondPage.performSearch("search") 

    then: "result should show" 
    secondPage.resultBox == "" 
} 
} 
+0

트릭을 한 덕분에 :) –