私は自分のサイトで可能な競合条件をテストしようとしているので、2つの異なるブラウザで正確に同時に実行する2つのtestNGテストメソッド(セレン2.0を使用)が必要です。 Eclipse(Indigo)用のtestNGプラグインを使用しています。タイミングは重要です。なぜなら、2つの更新が同時に実行され、例外がスローされるかどうかを確認したいからです。 testng.xmlの 'parallel'属性をクラス、テスト、メソッドに設定しようとしましたが、一方のテストは常に先に開始されるため、同期がとれていません。また、1つのテストでは実行に時間がかかることがあります(数ミリ秒)ので、タイミングを正しく取得する方法がわかりません。2つのtestNGテストメソッドを同時に実行し、同時に同じ時間に実行するタイミング?
今のところ私は2つの異なるクラスのテストを受けています。これは私が望むものに最も近い結果をもたらします。
クラス1:
public class SyncTest {
WebDriver driver;
WebElement element;
@BeforeMethod
public void setUp() throws Exception {
driver = new FirefoxDriver();
}
@Test(timeOut = 15000)
public void testSync() throws Exception {
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
//Login
driver.get("http://mySite.com");
driver.findElement(By.name("username")).sendKeys("admin");
driver.findElement(By.name("password")).sendKeys("admin");
try {
element = driver.findElement(By.id("centralLogin_0"));
element.click();
} catch (Exception e){
System.out.println("Error submitting: " + e.toString());
}
//open issue
driver.findElement(By.linkText("Sync Test")).click();
driver.switchTo().frame("mobile_vault");
//Change status
Select select = new Select(driver.findElement(By.id("statusSelect")));
//select.deselectAll();
select.selectByVisibleText("Open");
List <WebElement> elements;
//driver.findElement(By.className("button nextDialogue")).click();
try {
driver.findElement(By.cssSelector("div.button.nextDialogue > div")).click();
} catch (Exception e){
System.out.println("Not found");
}
Thread.sleep(2000);
try {
driver.findElement(By.xpath("//form[@id='frmcall']/fieldset/div[14]/div[2]/div[1]")).click();
} catch (Exception e) {
System.out.println("Not Found");
System.out.println(e.toString());
}
Thread.sleep(3000);
driver.navigate().refresh();
}
@AfterMethod
public void tearDown() {
driver.quit();
}
}
これはクラス2である:
public class NewSyncTest {
WebDriver driver;
WebElement element;
@Test
public void testF() throws Exception {
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
//Login
driver.get("http://mySite.com");
driver.findElement(By.name("username")).sendKeys("admin");
driver.findElement(By.name("password")).sendKeys("admin");
try {
element = driver.findElement(By.id("centralLogin_0"));
element.click();
} catch (Exception e){
System.out.println("Error submitting: " + e.toString());
}
//open admin page
driver.get("http://mySite.com/admin");
Thread.sleep(2000);
try {
driver.findElement(By.cssSelector("input[type='submit']")).click();
} catch (Exception e){
System.out.println("Not found");
}
}
@BeforeMethod
public void beforeMethod() {
driver = new FirefoxDriver();
}
@AfterMethod
public void afterMethod() {
driver.quit();
}
}
私は私のようになりますかわからないんだけどとしてTestNGのアノテーションの私の使用は、おそらく間違っている実感します最高(@BeforeSuite、@BeforeMethodなど)
私のtestng.xmlは次のようになります:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="classes">
<test name="Test" preserve-order="false">
<classes>
<class name="syncTest.SyncTest"/>
<class name = "syncTest.NewSyncTest"/>
</classes>
</test>
</suite>
私はテストが並行して正確に実行したことがないと私はまた、各テストメソッドの時間に注意し、以下のTestNG-results.xmlが含まれるだろう:(これを達成する方法がわからない言ったように:
<test name="Test" duration-ms="20264" started-at="2012-02-27T15:52:02Z" finished- at="2012-02-27T15:52:23Z">
<class name="syncTest.SyncTest">
<test-method status="PASS" signature="setUp()[pri:0, instance:[email protected]]" name="setUp" is-config="true" duration-ms="8475" started-at="2012-02-27T15:52:02Z" finished-at="2012-02-27T15:52:11Z">
</test-method>
<test-method status="PASS" signature="testSync()[pri:0, instance:[email protected]]" name="testSync" duration-ms="11556" started-at="2012-02-27T15:52:11Z" finished-at="2012-02-27T15:52:22Z">
</test-method>
<test-method status="PASS" signature="tearDown()[pri:0, instance:[email protected]]" name="tearDown" is-config="true" duration-ms="217" started-at="2012-02-27T15:52:22Z" finished-at="2012-02-27T15:52:23Z">
</test-method>
</class>
<class name="syncTest.NewSyncTest">
<test-method status="PASS" signature="beforeMethod()[pri:0, instance:[email protected]]" name="beforeMethod" is-config="true" duration-ms="4345" started-at="2012-02-27T15:52:02Z" finished-at="2012-02-27T15:52:07Z">
</test-method>
<test-method status="PASS" signature="testF()[pri:0, instance:[email protected]]" name="testF" duration-ms="9728" started-at="2012-02-27T15:52:07Z" finished-at="2012-02-27T15:52:16Z">
</test-method>
<test-method status="PASS" signature="afterMethod()[pri:0, instance:[email protected]]" name="afterMethod" is-config="true" duration-ms="231" started-at="2012-02-27T15:52:16Z" finished-at="2012-02-27T15:52:17Z">
</test-method>
</class>
</test>
任意のすべての提案を歓迎します。前もって感謝します! :)
下記のお返事ありがとうございます。ハイパフォーマンスマーク、私はあなたのポイントを参照してください。私はテストしようとしていることを説明します:私はデータベース内のデータのセットとこのデータに対する2つのビュー(中央とクライアント)を持っています。 2つのビューは明らかに同期している必要があります。 1つ(ユーザーによって)で行われた変更は、もう1つに反映されます。上の私の最初のテストケースでは、ユーザーがフォームを編集し、submitをクリックします。 2番目のWebアクションは、すべての項目の編集をチェックしてDBに保存するWebアクションを呼び出します。ユーザーが編集を行い、同時にこのチェックが行われた場合、その編集内容は失われる可能性がありますか?小切手では編集が見られませんでしたか? – user1088166
あなたが説明しようとしたこのシナリオは[phantom read](http://en.wikipedia.org/wiki/Isolation_(database_systems)#Phantom_reads)のようなものです。ロックを使って簡単に克服することができます。詳細については、[this](http://docstore.mik.ua/orelly/java-ent/ebeans/ch08_03.htm)を参照してください。 – Bala
また、一般的に小さなテスト(並行して起こる)を扱うユニットテスト環境では、このような状況を再現することは非常に困難です。 – Bala