オブジェクトを正しくインスタンス化して他のメソッドに渡すのに苦労しています。これが私のコードです:
public class CreateAndDeleteCollector {
private static WebDriver driver = new FirefoxDriver();
private LoginPage login;
private AdminRtcpCollectorPage rtcp;
private AdminFunctions admin;
//DesiredCapabilities capability = DesiredCapabilities.firefox();
//String hubUrl = "http://localhost:4444/wd/hub";
//WebDriver d = new RemoteWebDriver(new URL(hubUrl), capability);
@BeforeMethod
public void setup() throws Exception {
LoginPage login = new LoginPage(driver);
AdminRtcpCollectorPage rtcp = new AdminRtcpCollectorPage(driver);
AdminFunctions admin = new AdminFunctions();
}
@Test
public void newCollector() throws Exception {
login.login("192.168.1.100", "admin", "admin");
rtcp.goToRtcpCollectorPage();
rtcp.newRtcpCollector("test-1", "test", "test", "192.168.1.100");
}
@Test(dependsOnMethods = { "newCollector" })
public void deleteCollector() throws Exception {
admin.initialize(driver);
rtcp.goToRtcpCollectorPage();
admin.delete("test-1");
}
@AfterTest
public void logoutAndClose() {
Util.logout(driver);
driver.close();
}
}
最初のテスト メソッドに到達するとすぐに TestNG を使用してこれを実行すると、ログイン、rtcp、および管理者のために NullPointerException でエラーが発生します。@BeforeMethod アノテーションが何をすべきかを誤解していると確信しています。
ちなみに、すべての宣言を置き、setup メソッドの外でインスタンス化することもできますが、これはうまく機能しますが、それらをメソッドに入れる理由は、RemoteWebDriver 行にコメントすると、「デフォルトのコンストラクターは例外タイプを処理できません。 .." エラー。
誰か提案はありますか?
TestNG の factory と dataprovider を使用することが答えになると思いますが、それを自分の状況に適用する方法がわかりません。