0

ファイルの HTML バージョンを実行すると、低速モードで動作します (高速モードでは失敗します)。

Java の setspeed メソッドを使用してみましたが、うまくいきませんでした (おそらく、後のバージョンで減価償却されたためです)。次に、手動のスレッド ウェイト時間を追加しようとしましたが (失敗するスポットの前に)、それも失敗しています。

とにかく、ここに私のJavaコードがあります:

import com.thoughtworks.selenium.Selenium;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverBackedSelenium;
import org.openqa.selenium.WebElement;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.thoughtworks.selenium.SeleneseTestBase;

public class tradePagesNotLoad extends SeleneseTestBase{
private Selenium selenium;

@Before
public void setUp() throws Exception {
    WebDriver driver = new FirefoxDriver();
    String baseUrl = "http://www.fsdafdscsa.com/";
    selenium = new WebDriverBackedSelenium(driver, baseUrl);
}

@Test
public void testA9() throws Exception {
    selenium.open("");
    selenium.click("link=Sign In");
    selenium.waitForPageToLoad("30000");
    selenium.type("id=login_username", "fsadfsa");
    selenium.type("id=login_password", "asweqr");
    selenium.click("name=login_button");
    selenium.waitForPageToLoad("30000");
    verifyTrue(selenium.isElementPresent("link=Sign Out"));
    selenium.click("link=Trade");
    selenium.waitForPageToLoad("30000");
    String sellButtonText = selenium.getText("xpath=(//button[@type='button'])[7]");
    System.out.println(sellButtonText);


    assertNotEquals("Loading...", selenium.getEval("storedVars['sellButtonText']"));
    String buyButtonText = selenium.getText("xpath=(//button[@type='button'])[8]");
    System.out.println(buyButtonText);
    assertNotEquals("Loading...", selenium.getEval("storedVars['buyButtonText']"));
    String bidPrice = selenium.getText("id=pretty_bid_price");
    System.out.println(bidPrice);
    assertNotEquals("Loading...", selenium.getEval("storedVars['bidPrice']"));
    String askPrice = selenium.getText("id=pretty_ask_price");
    System.out.println(askPrice);
    assertNotEquals("Loading...", selenium.getEval("storedVars['askPrice']"));
}

@After
public void tearDown() throws Exception {
    selenium.stop();
}
}

コードは最初の assertNotEquals で失敗しています。任意の提案をいただければ幸いです。

4

3 に答える 3

0

私の Java 自動化フレームワークでは、WebDriver$Timeouts.class インターフェイス - 暗黙的に待機 (長い時間、TimeUnit 単位) メソッドを使用します。あなたの場合、オブジェクト Webdriver のインスタンスを初期化した直後に、以下のコードを貼り付けます。

driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

このメソッドは、要素がすぐに存在しない場合に、要素を検索するときにドライバーが待機する時間を指定します。

お役に立てれば。

于 2014-05-20T10:15:28.210 に答える
0

私は Java と Selenium にあまり詳しくありませんが、文字列に保存した storedVars 配列内の何かにアクセスしようとしているように見えます。

String sellButtonText = selenium.getText("xpath=(//button[@type='button'])[7]");

そしてその後

assertNotEquals("Loading...", selenium.getEval("storedVars['sellButtonText']"));

selenium.store配列を使いたい場合のようなものを使うべきではありませんstoredVarsか?

于 2013-09-18T12:01:36.157 に答える