0

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);
        }
Vlad Honya
  • 160
  • 3
  • 13
  • Possible duplicate of [What is a NullPointerException, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – JeffC Apr 16 '17 at 04:51
  • You should spend some time learning how to use your IDE to debug your test. Stepping through the code should show you where the error is. – JeffC Apr 16 '17 at 04:51

0 Answers0