2016-07-20 8 views
1

なぜ次の例では3つのクロムブラウザが開かれているのか分かりません。シナリオが実行される前にクロムウェブドライバのインスタンスを設定するための@Before(キュウリバージョン)注釈があります。限り、私は見ることができる、それは@Afterキュウリのフックを使用して閉じるシナリオ(ステップdefs)を実行し、1つのブラウザを開く必要があります。何が起こるかというと3番目と最後の窓の前に開いている2つのウィンドウは、実際の手順を実行している:デフキュウリ@Beforeフック複数のブラウザウィンドウを開く

Scenario: 
    Given I am on the holidays homepage 
    When I select the departure location "LON" 
    And I select the destination location "PAR" 
    And I submit a search 
    Then search results are displayed 

ステップ:

public class FindAHolidayStepDefs { 

    private WebDriver driver; 

    @Before 
    public void setup() { 
     System.setProperty("webdriver.chrome.driver", 
       System.getProperty("user.dir") + "\\drivers\\chromedriver.exe"); 
     driver = new ChromeDriver(); 
    } 

    @Given("^I am on the Holidays homepage$") 
    public void IAmOnTheThomasCookHomepage() { 
     driver.get("http://uat7.co-operativetravel.co.uk/"); 
     driver.manage().window().maximize(); 
     String pageTitle = driver.getTitle(); 

     assertEquals("the wrong page title was displayed !", "Holidays - welcome", pageTitle); 
    } 


    @When("^I select the departure location \"([^\"]*)\"$") 
    public void ISelectTheDepartureLocation(String departureAirport) { 
     WebElement dropDownContainer = driver.findElement(By.xpath("(//div[@class=\"custom-select departurePoint airportSelect\"])[1]")); 
     dropDownContainer.click(); 

     selectOption(departureAirport); 
    } 

    @When("^I select the destination location \"([^\"]*)\"$") 
    public void ISelectTheDestinationLocation(String destinationAirport) { 
     WebElement destinationField = driver.findElement(By.xpath(("(//div[@class=\"searchFormCol destinationAirport\"]/div[@class=\"combinedInput searchFormInput\"]/span/input)[1]"))); 
     destinationField.sendKeys(destinationAirport); 
     selectOption("(" + destinationAirport + ")"); 
    } 


    @When("^I submit a search$")public void iSubmitASearch() throws Throwable { 
     WebElement submitButton = driver.findElement(By.xpath("(.//*[@type='submit'])[1]")); 
     submitButton.click(); 
    } 


    @Then("^search results are displayed$") 
    public void searchResultsAreDisplayed() throws Throwable { 
     waitForIsDisplayed(By.xpath(".//*[@id='container']/div/div[3]/div/div[1]/div/h3"), 30); 
     assertThat(checkPageTitle(), equalTo("Package Results")); 
    } 


    @After 
    public void tearDown() { 
     driver.quit(); 
    } 
} 

私はのIntelliJのコードをステップ実行すると、以下のメソッドが呼び出されます。

とIntellijは、この時点でフックparamter = 3を報告します。

hooks: size=3 reporter: "null" tags: size = 0 isBefore: true 

答えて

0
  • あなたの機能の1つのシナリオ、より多くを持っていますか? - >各シナリオの前に@Beforeメソッドが実行されます。
  • chromeを開く@Before注釈付きメソッドとは異なるstepdefクラスがありますか? - > @すべての@メソッドは、シナリオが実行される前に呼び出されます。
+0

"あなたの機能には複数のシナリオがありますか?" - いいえ、1つのシナリオ "、"クロムを開く@Before注釈付きメソッドで別のstepdefクラスを持っていますか? ! – Steerpike

+0

申し訳ありませんが、あなたは正しかったです。@Beforeも2つのクラスで2回呼び出されていました – Steerpike

関連する問題