1

いくつかのアサートを行う前に、Selenium2にすべてのリダイレクトに従うように強制するにはどうすればよいですか?

  Scenario: Guest member can pay with card
    When I go to "/test"
    #test page redirects to "/auth" which then redirects to "/main"
    Then I should be redirected to "/main"

私は単に待つことができると考えました:

  /**
   * @Then /^I should be redirected to "([^"]*)"$/
   */
  public function assertRedirect($url)
  {
    $this->getSession()->wait(10000);

    $this->assertPageAddress($url);
  }

問題は、どれだけ長く待っても、常に「/main」ではなく「/auth」ページに表示されることです。

更新:問題は神話であり、セレンは特別なことを何もしておらず、ブラウザは通常どおりデフォルトでリダイレクトに従います。私の場合、リダイレクトを生成するはずだったページが実際に200応答を送信していました。

4

1 に答える 1

0

私はあなたと同じような状況に遭遇しました。要素が表示可能になるのを待機する x 秒の間、​​要素を毎秒ポーリングする待機メソッドを設定しました。次に、最後のページでのみ使用可能な要素、またはあなたの場合は /main に Xpath を渡します。これが私がJavaで使用する方法です。

 public void waitForElement(WebDriver driver, final String xpath)
 {
     //Set up fluentWait to wait for 35 seconds polling every 1
     Wait<WebDriver> fluentWait = new FluentWait<WebDriver>(driver)
         .withTimeout(35, TimeUnit.SECONDS)
         .pollingEvery(1, TimeUnit.SECONDS)
         .ignoring(NoSuchElementException.class);

     WebElement element;

     //Look for element, if not found start fluentWait
     try
     {
         element = driver.findElement(By.xpath(xpath));
     }
     catch (WebDriverException e)
     {
         logger.info("[getElementByXpath] Element not initially found. Starting fluentWait ["+xpath+"]");

         try
         {
             element = fluentWait.until(new Function<WebDriver, WebElement>() {
                 public WebElement apply(WebDriver d) {

                     return d.findElement(By.xpath(xpath));
                 }
             });
         }
         catch (WebDriverException f)
         {
             logger.info("[getElementByXpath] FluentWait findElement threw exception:\n\n" + f +"\n\n");

             throw new WebDriverException("Unable to find element ["+xpath+"]");
         }
     }

     //Once we've found the element wait for element to become visible
     fluentWait.until(ExpectedConditions.visibilityOf(element));
 }

要素が返されたときに正しい /main ページにいるため、可視性のために最後の fluentWait が必要な場合とそうでない場合があります。

お役に立てれば。幸運を!

于 2012-10-04T15:23:37.147 に答える