title: Java. Selenium. Mobile automation. An error occurred while instantiating class <someclass>: null
body: <p>I try to run automation script for testing of my Android device (Java+Selenium+Appium). According to the task I should run my test class with extends class (<code>extends BaseWebDriverTest</code>). When I run the test without extends everything is OK but with it my test failed with error: </p>
  
  <pre><code>org.testng.TestNGException: 
  An error occurred while instantiating class auto.test.TestSample: null
      at org.testng.internal.ClassHelper.createInstance1(ClassHelper.java:398)
      at org.testng.internal.ClassHelper.createInstance(ClassHelper.java:299)
      at org.testng.internal.ClassImpl.getDefaultInstance(ClassImpl.java:115)
      at org.testng.internal.ClassImpl.getInstances(ClassImpl.java:200)
      at org.testng.internal.TestNGClassFinder.&lt;init&gt;(TestNGClassFinder.java:120)
      at org.testng.TestRunner.initMethods(TestRunner.java:409)
      at org.testng.TestRunner.init(TestRunner.java:235)
      at org.testng.TestRunner.init(TestRunner.java:205)
      at org.testng.TestRunner.&lt;init&gt;(TestRunner.java:160)
      at org.testng.remote.RemoteTestNG$1.newTestRunner(RemoteTestNG.java:141)
      at org.testng.remote.RemoteTestNG$DelegatingTestRunnerFactory.newTestRunner(RemoteTestNG.java:271)
      at org.testng.SuiteRunner$ProxyTestRunnerFactory.newTestRunner(SuiteRunner.java:575)
      at org.testng.SuiteRunner.init(SuiteRunner.java:159)
      at org.testng.SuiteRunner.&lt;init&gt;(SuiteRunner.java:113)
      at org.testng.TestNG.createSuiteRunner(TestNG.java:1299)
      at org.testng.TestNG.createSuiteRunners(TestNG.java:1286)
      at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
      at org.testng.TestNG.run(TestNG.java:1057)
      at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
      at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
      at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
      at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:125)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:483)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
  Caused by: java.lang.ExceptionInInitializerError
      at auto.framework.pageframework.util.drivers.WebDriverWrapper.&lt;clinit&gt;(WebDriverWrapper.java:67)
      at auto.framework.test.BaseWebDriverTest.&lt;clinit&gt;(BaseWebDriverTest.java:29)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
      at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:29)
      at org.testng.internal.ClassHelper.createInstance1(ClassHelper.java:387)
      ... 26 more
  Caused by: java.lang.IllegalArgumentException: No enum constant auto.framework.pageframework.util.environment.Browser.
      at java.lang.Enum.valueOf(Enum.java:238)
      at auto.framework.pageframework.util.environment.Browser.valueOf(Browser.java:9)
      at auto.framework.pageframework.util.environment.EnvironmentUtil.setBrowser(EnvironmentUtil.java:877)
      at auto.framework.pageframework.util.environment.EnvironmentUtil.&lt;clinit&gt;(EnvironmentUtil.java:129)
      ... 34 more
  
  Process finished with exit code 0
  </code></pre>
  
  <p>Appium server works fine. </p>
  
  <p>Here is my code:</p>
  
  <pre><code>package auto.test;
  
  import io.appium.java_client.AppiumDriver;
  import io.appium.java_client.android.AndroidDriver;
  import org.apache.log4j.Logger;
  import org.openqa.selenium.By;
  import org.openqa.selenium.WebElement;
  import org.openqa.selenium.remote.CapabilityType;
  import org.openqa.selenium.remote.DesiredCapabilities;
  
  import auto.framework.test.BaseWebDriverTest;
  import auto.pageframework.testdata.TestConstants;
  import org.testng.Assert;
  import org.testng.annotations.BeforeMethod;
  import org.testng.annotations.Test;
  
  import java.io.File;
  import java.net.MalformedURLException;
  import java.net.URL;
  import java.util.concurrent.TimeUnit;
  
  
  public class TestSample extends BaseWebDriverTest {
  
      private static final Logger logger = Logger.getLogger(TestSample.class);
  
      AppiumDriver driver;
  
      @BeforeMethod(alwaysRun = true)
      public void testSetup() throws MalformedURLException {
  
          File classpathRoot = new File(System.getProperty("user.dir"));
          File appDir = new File(classpathRoot, "/wholefoods");
          File app = new File(appDir, "com.wholefoods.wholefoodsmarket.apk");
  
          DesiredCapabilities capabilities = new DesiredCapabilities();
  
          capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
          capabilities.setCapability("platformName", "Android");
          capabilities.setCapability(CapabilityType.VERSION, "4.4.2");
          capabilities.setCapability("deviceName", "J509B1ZB46180A57");
          capabilities.setCapability("app", app.getAbsolutePath());
          capabilities.setCapability("appPackage", "com.wholefoods.wholefoodsmarket");
          capabilities.setCapability("appActivity", "com.wholefoods.wholefoodsmarket.application.activities.WFMSplashActivity");
          this.driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
      }
  
      @Test(groups = { TestConstants.TestNGGroups.REG }, description = "")
      public void testSearchingForCoffeeFood() {
  
          driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
  
          Boolean searchFieldIsPresent = driver.findElements(By.id("etHomeSearch")).size() &gt; 0;
          Assert.assertTrue(searchFieldIsPresent, "Search field with id='etHomeSearch' is absent.");
          WebElement searchField = driver.findElement(By.id("etHomeSearch"));
          searchField.clear();
          searchField.sendKeys("Coffee");
  
          Boolean searchButtonIsPresent = driver.findElements(By.id("imgSearch")).size() &gt; 0;
          Assert.assertTrue(searchButtonIsPresent, "Search button with id='imgSearch' is absent.");
          WebElement searchButton = driver.findElement(By.id("imgSearch"));
          searchButton.click();
  
          Boolean pageTitleIsPresent = driver.findElement(By.id("header_title")).getText().equals("SEARCH");
          Boolean searchResultIsPresent = driver.findElements(By.id("recipesSearchResultsGrid")).size() &gt; 0;
  
  }
  </code></pre>
  
  <p>Here is the code of extends class:</p>
  
  <pre><code>package auto.framework.test;
  
  import auto.framework.pageframework.synchronization.AjaxHelper;
  import framework.pageframework.util.drivers.WebDriverWrapper;
  import framework.pageframework.util.environment.EnvironmentUtil;
  import auto.framework.test.TestListener;
  import org.apache.log4j.Logger;
  import org.openqa.selenium.WebDriver;
  import org.testng.annotations.AfterClass;
  import org.testng.annotations.AfterMethod;
  import org.testng.annotations.Listeners;
  
  @Listeners({TestListener.class})
  public class BaseWebDriverTest {
      protected static WebDriver driver = null;
      protected static AjaxHelper syncHelper = new AjaxHelper(WebDriverWrapper.getWebDriver());
      protected static EnvironmentUtil env = EnvironmentUtil.getInstance();
      protected static Logger logger = Logger.getLogger(BaseWebDriverTest.class);
  
      public BaseWebDriverTest() {
      }
  
      @AfterClass(
          alwaysRun = true
      )
      public static void suiteTearDown() {
          if(!env.getIsRemoteTestRun()) {
              WebDriverWrapper.closeBrowser(driver);
          }
  
      }
  
      @AfterMethod(
          alwaysRun = true
      )
      public void testTearDown() {
          logger.warn("========================== Completed test ==============================");
      }
  
      static {
          logger.info("calling get WebDriver()");
          driver = WebDriverWrapper.getWebDriver();
      }
  }
  </code></pre>
  
  <p>Here is my <code>Browser</code> class:</p>
  
  <pre><code>public enum Browser {
      FIREFOX,
      CHROME,
      SAFARI,
      IE,
      LOCAL_SIMULATED_NEXUS_SEVEN,
      LOCAL_SIMULATED_IPAD_THREE,
      BS_FIREFOX_31,
      BS_FIREFOX_35_LS,
      BS_IE_10,
      BS_IE_11,
      BS_IE_11_LS,
      BS_CHROME_36,
      BS_CHROME_39,
      BS_CHROME_39_LS,
      BS_SAFARI_7_MAC,
      LOCAL_NEXUS_SEVEN_MOBILE_WEB,
      LOCAL_NEXUS_SEVEN_DEVICE,
      LOCAL_ANDROID_MOBILE,
      LOCAL_ANDROID_TABLET,
      SIM_IPAD_MOBILE_WEB,
      SIM_IPHONE_MOBILE_WEB,
      LOCAL_SIM_IPHONE_FIVE,
      LOCAL_SIM_IPHONE_FIVE_S,
      LOCAL_SIM_IPHONE_SIX,
      LOCAL_SIM_IPHONE_SIX_PLUS,
      LOCAL_SIM_IPAD,
      LOCAL_IPAD_DEVICE,
      LOCAL_IPHONE_DEVICE,
      LOCAL_GENERIC_DEVICE,
      LOCAL_GENERIC_DRIVER,
      REMOTE_CHROME,
      REMOTE_FIREFOX,
      REMOTE_INTERNETEXPLORER,
      REMOTE_SAFARI,
      REMOTE_SIMULATED_NEXUS_SEVEN,
      REMOTE_SIMULATED_IPAD,
      APPTHWACK_SAFARI_IOS,
      APPTHWACK_NEXUS_SEVEN,
      APPTHWACK_NEXUS_FIVE,
      APPTHWACK_IPHONE_SIX,
      APPTHWACK_IPAD_FOUR,
      TD_NEXUS_SEVEN_CHROME_WEB,
      TD_NEXUS_SEVEN,
      TD_NEXUS_FIVE,
      TD_GALAXY_S_THREE,
      TD_IPAD_SAFARI_WEB,
      TD_IPAD,
      TD_IPHONE_SIX;
  
      private Browser() {
      }
  }
  </code></pre>
  
  <p>and this is the part of <code>EnvironmentUtil</code>:</p>
  
  <pre><code>public class EnvironmentUtil {
  private static Logger logger = Logger.getLogger(EnvironmentUtil.class);
  private static Browser browser;
  private static String deviceName;
  private static String platformVersion;
  private static String url;
  private static String testPlanId;
  private static String testRunId;
  private static String snapshotDirectory;
  private static Boolean takeSnapShots = Boolean.valueOf(true);
  private static Boolean setLogToDebug = Boolean.valueOf(false);
  private static Boolean logResults = Boolean.valueOf(false);
  private static Boolean failedTestDoReset = Boolean.valueOf(false);
  private static String webDriverGridUrl = "";
  private static Boolean isMobileTest = Boolean.valueOf(false);
  private static int appThwackProjectId = 0;
  private static String appThwackApiKey = "";
  private static int appThwackAppId = 0;
  private static String appiumGridUrl;
  private static String appPackage;
  private static String appActivity;
  private static String testDroidUserName = "";
  private static String testDroidPassword = "";
  private static String testDroidProjectName = "";
  private static String testDroidProjectDescription = "";
  private static String testDroidTestRun = "";
  private static String testDroidServer = "";
  private static String targetAppPath = "";
  private static String testGroup = "";
  private static boolean rawCssOnly = false;
  private static String previousWindowHandle = "";
  private static boolean isMobileIOS = false;
  private static boolean isTablet = false;
  private static boolean isPhablet = false;
  private static boolean isSimulator = false;
  private static boolean isPhone = false;
  private static boolean isAndroidTablet = false;
  private static String browserStackUserName = "";
  private static String browserStackKey = "";
  private static String iosBundleID = "";
  private static String iosUdid = "";
  private static boolean noSign = false;
  private static boolean isJenkinsRun = false;
  private static String jenkinsURL = "";
  private static boolean isRemoteTestRun = false;
  private static String dataProvider = "null";
  private static String testRailUrl = "";
  private static String testRailUserName = "";
  private static String testRailPassword = "";
  private static Map&lt;String, String&gt; locators = new HashMap();
  private static boolean sizzleInjection = false;
  private static String caseId = "";
  private static EnvironmentUtil instance = new EnvironmentUtil();
  
  public static EnvironmentUtil getInstance() {
          return instance;
      }
  </code></pre>
  
  <p>Help me please how can I fix this problem! Thank you!</p>