Java Selenium Junit在优化速度测试中的应用
问题是优化测试的速度。我有4个浏览器 而每个人都会在很长一段时间内通过考试。使用 最后,我试图确保我的浏览器进行了测试并 立即刷新,测试结束时,浏览器被关闭 完全封闭。但是我在69行drv.get(“文件:/// D:/UICalcUpdate.html”);NullPointerException。Xmll文件和测试 在没有成功优化的情况下工作)Java Selenium Junit在优化速度测试中的应用,java,selenium,junit,Java,Selenium,Junit,问题是优化测试的速度。我有4个浏览器 而每个人都会在很长一段时间内通过考试。使用 最后,我试图确保我的浏览器进行了测试并 立即刷新,测试结束时,浏览器被关闭 完全封闭。但是我在69行drv.get(“文件:/// D:/UICalcUpdate.html”);NullPointerException。Xmll文件和测试 在没有成功优化的情况下工作) 包权BTNCALC; 导入静态org.junit.Assert.*; 导入java.util.array; 导入java.util.Collecti
包权BTNCALC;
导入静态org.junit.Assert.*;
导入java.util.array;
导入java.util.Collection;
导入org.junit.After;
导入org.junit.AfterClass;
导入org.junit.Before;
导入org.junit.BeforeClass;
导入org.junit.Test;
导入org.junit.runner.RunWith;
导入org.junit.runners.Parameterized;
导入org.junit.runners.Parameterized.Parameters;
导入org.openqa.selenium.By;
导入org.openqa.selenium.WebDriver;
导入org.openqa.selenium.chrome.ChromeDriver;
导入org.openqa.selenium.firefox.FirefoxDriver;
导入org.openqa.selenium.ie.InternetExplorerDriver;
导入org.openqa.selenium.opera.OperaDriver;
公共阶级存在{
静态WebDriver drv=null;
@RunWith(参数化的.class)
公共静态类存在性测试{
静态字符串str=“”;
@参数
公共静态收集数据()
{
返回Arrays.asList(新对象[][]
{
{“IE”},
{“Chrome”},
{“Firefox”},
{“歌剧”}
});
}
公共存在测试(字符串s){
str=s;
}
@课前
公共静态void reflechcalc(){
开关(str){
案例“IE”:
System.setProperty(“webdriver.ie.driver”,“D:\\IEDriverServer.exe”);
drv=新的InternetExplorerDriver();
打破
案例“铬”:
System.setProperty(“webdriver.chrome.driver”,“D:\\chromedriver.exe”);
drv=新的ChromeDriver();
打破
案例“Firefox”:
System.setProperty(“webdriver.gecko.driver”,“D:\\geckodriver.exe”);
drv=新的FirefoxDriver();
打破
“歌剧”一案:
System.setProperty(“webdriver.opera.driver”,“D:\\operadriver.exe”);
drv=新操作驱动程序();
打破
}
drv.get(“file:///D:/UICalcUpdate.html");
}
@之后
public void testCloseCalc(){
drv.quit();
}
@以前
公共作废设置()
{
drv.navigate().refresh();
}
@试验
公共无效测试\u btn0()
{
String res=drv.findElement(By.id(“btn0”)).getAttribute(“value”);
资产质量(“0”,res);
}
您应该花一些时间学习如何使用IDE调试测试。单步执行代码应该会告诉您错误所在。
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);
}