在我的測試中,我要在一種方法中捕獲一個字符串,然後以不同的方法使用它。以下是我正在嘗試執行的一個示例:如何使用TestNG將字符串從一種方法傳遞給另一種方法?
public class stackOverflowExample {
public static WebDriver driver;
public static Properties OR = null;
@Test
public void test_1() throws InterruptedException {
System.setProperty("webdriver.ie.driver","D:\\iedriver\\IEDriverServer.exe");
driver=new InternetExplorerDriver();
driver.get("http://www.google.com");
Thread.sleep(1500);
String string1 = driver.findElement(By.id("btnK")).getText();
System.out.println(string1);
}
public void test_2() {
System.out.println(string1);
}
}
如何在test_2()方法中使用string1?
*編輯:
對於爲什麼我試圖做到這一點清晰,我運行一個測試,執行以下操作:
- 登錄到網站的用戶1
- 下創建一個新的抵押貸款應用程序
- 註銷用戶1,然後重新登錄到用戶2下
- 然後,用戶2將打開新創建的抵押貸款應用程序並運行各種測試場景。
使它成爲全球上課? – amkz
我對這方面有限的知識表示歉意。我對此很新。我將如何去使其成爲全球? –