The problem is to optimize the speed of the test. I have 4 browsers while everyone will pass the test for a very long time. Using the anotations, I tried to make sure that my browser did the test and immediately refreshed and when the test ended the browser was perfectly closed. But I have a bug in the 69 line drv.get ("file: /// D: / UICalcUpdate.html"); NullPointerException. Xmll file and tests working without my unsuccessful optimization).
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);
}