java + testngでselenium webdriverを使用してアプリケーションGUIをテストしています。私は私のプロジェクト(同じパッケージ)に2つのクラスファイルを持っています。 1クラスファイルにはすべての@Testメソッドがあり、2つ目のクラスファイルには、ファーストクラスファイルのテストメソッドで生成されたIDを持つExcelファイルを生成するための1つのメソッドがあります。基本的に私のAUTは、私がキャプチャする必要があるテストメソッドを実行するたびに一意のIDを生成します。今、私はできません1クラスファイルの@Testメソッドから他のクラスファイル(testNG)の注釈付きメソッドにパラメータを渡す方法
@BeforeClass
public void createExcel() throws IOException
{
System.out.println("did this run");
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet("IncidentNo");
//some code to save uniqueID in excel file
}
- 同じパッケージ内に第二のクラスファイルで
@Test (invocationCount = 1)
public void TestIncident() {
ProfilesIni profile = new ProfilesIni();
FirefoxProfile myprofile = profile.getProfile("selenium");
WebDriver driver=new FirefoxDriver(myprofile);
vDriver = driver;
driver.manage().window().maximize();
driver.get("URL");
driver.findElement(By.id("username-id")).click();
driver.findElement(By.id("username-id")).sendKeys("username");
driver.findElement(By.id("pwd-id")).click();
driver.findElement(By.id("pwd-id")).sendKeys("password");
driver.findElement(By.name("login")).click();
Thread.sleep(5000);
driver.findElement(By.id("reg_img_304316340")).click();
driver.findElement(By.xpath("//div[@class='PageBody pbChrome']"));
//new Actions(driver).moveToElement(driver.findElement(By.xpath("//div[@class='PageBody pbChrome']"))).perform();
driver.findElement(By.xpath("//span[contains(.,'Page1')]")).click();
driver.findElement(By.xpath("//span[contains(.,'New Page')]")).click();
driver.findElement(By.xpath("//div[@class='PageBody pbChrome']")).click();
uniqueID = driver.findElement(By.xpath("//div[@id='WIN_0_304248710']/descendant::dd[@class='HNavSelected arfid304247442 ardbnz3Btn_BCItem3']/descendant::a[@class='btn']")).getAttribute("innerHTML");
driver.findElement(By.id("arid_WIN_3_303530000")).clear();
driver.findElement(By.id("arid_WIN_3_303530000")).click();
}
ファーストクラスファイルに 試験方法、私はこのような何かをやっている - このようになります
コードファーストクラスファイルの@Test
メソッドからのuniqueID
を、ファーストクラスファイルのメソッドに送信して、これらのユニークIDをExcelシートに保存する方法を見つけます。これを達成するための効果的な方法は何ですか?