问题是优化测试速度。我有4个浏览器 虽然每个人都会通过测试很长一段时间。使用 anotations,我试图确保我的浏览器进行了测试 立即刷新,当测试结束时,浏览器是 完全关闭。但我在69行drv.get中有一个错误(“file:/// D:/ UICalcUpdate.html“); NullPointerException。Xmll文件和测试 没有我不成功的优化工作)。
package RightBtnCalc;
import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.Collection;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.opera.OperaDriver;
public class Existence {
static WebDriver drv = null;
@RunWith(Parameterized.class)
public static class ExistenceTest {
static String str = "";
@Parameters
public static Collection<Object[]> data()
{
return Arrays.asList(new Object[][]
{
{ "IE" },
{ "Chrome" },
{ "Firefox" },
{ "Opera" }
});
}
public ExistenceTest(String s) {
str = s;
}
@BeforeClass
public static void RefrechCalc() {
switch (str) {
case "IE":
System.setProperty("webdriver.ie.driver", "D:\\IEDriverServer.exe");
drv = new InternetExplorerDriver();
break;
case "Chrome":
System.setProperty("webdriver.chrome.driver","D:\\chromedriver.exe");
drv = new ChromeDriver();
break;
case "Firefox":
System.setProperty("webdriver.gecko.driver", "D:\\geckodriver.exe");
drv = new FirefoxDriver();
break;
case "Opera":
System.setProperty("webdriver.opera.driver","D:\\operadriver.exe");
drv = new OperaDriver();
break;
}
drv.get("file:///D:/UICalcUpdate.html");
}
@After
public void testCloseCalc() {
drv.quit();
}
@Before
public void setUP()
{
drv.navigate().refresh();
}
@Test
public void test_btn0()
{
String res = drv.findElement(By.id("btn0")).getAttribute("value");
assertEquals("0", res);
}