public class DemoTest {
private static final ThreadLocal<WebDriver> webDriverThreadLocal= new InheritableThreadLocal<>();
private String baseUrl;
Random random = new Random();
int no;
private final Map<Integer, String> map =new LinkedHashMap<Integer, String>();
@Test(dataProvider = "dp1")
public void f(Integer n, String s) {
WebDriver driver = webDriverThreadLocal.get();
no= random.nextInt(4);
map.put(no, "1234567");
}
@Test(dependsOnMethods = {"f"}, dataProvider = "dp2")
public void f1(Integer uname, String password){
System.out.println("uname:"+uname+" password:"+password);
System.out.println("In f1 id:"+Thread.currentThread().getId());
}
@BeforeMethod
public void beforeMethod() {
WebDriver driver= new FirefoxDriver();
// driver = ThreadGuard.protect(new FirefoxDriver());
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().maximize();
webDriverThreadLocal.set(driver);
System.out.println("Before method id:"+Thread.currentThread().getId());
}
@AfterMethod
public void afterMethod() {
WebDriver driver = webDriverThreadLocal.get();
System.out.println("After method id:"+Thread.currentThread().getId());
System.out.println("");
if(driver != null) {
driver.quit();
// driver.close();
}
}
@DataProvider(name ="dp1" ,parallel=true)
public Object[][] dp() {
return new Object[][] {
new Object[] { 1, "a" },
new Object[] { 2, "b" },
new Object[] { 3, "c" },
new Object[] { 4, "d" },
};
}
@DataProvider(name="dp2" , parallel=true)
public Iterator dp2() {
return this.map.entrySet().iterator();
}
- 測試f1取決於測試f。
- f1生成隨機數&輸入到測試f1的字符串。
- 我想將map Iterator從測試f傳遞到測試f1。
這是我到目前爲止嘗試過的。通過數據提供程序返回映射的迭代器
我得到以下錯誤:
java.lang.ClassCastException: java.util.LinkedHashMap$Entry cannot be cast to [Ljava.lang.Object;
如何解決這個問題?
你從哪裏得到錯誤?哪條線?是不是因爲你在dp()中使用了Object的二維數組? – Asoub