title: RemoteWebDriver is null error (sauce labs implementation) -selenium,cucumber,java
body: <p>I am implementing my code to work on remote machines on Sauce Labs. The code worked fine until I have changed my driver initialisation (to work with remote server). I keep getting this.driver is null exception. I don't know what's wrong with it, I was following official documentation and tried many things. I hope someone can see the issue here. Thank you in advance. My code:</p>
  <p><strong>DRIVER</strong>:(my username and key are copied from my sauce labs account, renamed for this purpose)</p>
  <pre><code>public class Hooks {
      public RemoteWebDriver driver;
      public WebDriverWait wait;
  
      @Before
      public void setup(Scenario scenario) throws MalformedURLException {
          String username = System.getenv(&quot;my username&quot;);
          String accessKey = System.getenv(&quot;key&quot;);
  
          ChromeOptions chromeOpts = new ChromeOptions();
          MutableCapabilities sauceOpts = new MutableCapabilities();
  
          sauceOpts.setCapability(&quot;name&quot;, scenario.getName());
          sauceOpts.setCapability(&quot;username&quot;, username);
          sauceOpts.setCapability(&quot;accessKey&quot;,accessKey);
  
         MutableCapabilities browserOptions = new MutableCapabilities();
         browserOptions.setCapability(ChromeOptions.CAPABILITY, chromeOpts);
         browserOptions.setCapability(&quot;sauce:options&quot;, sauceOpts);
         browserOptions.setCapability(&quot;browserName&quot;, &quot;chrome&quot;);
         browserOptions.setCapability(&quot;browserVersion&quot;, &quot;latest&quot;);
         browserOptions.setCapability(&quot;platformName&quot;, &quot;Windows 10&quot;);
  
         String sauceUrl = &quot;https://ondemand.us-west-1.saucelabs.com:443/wd/hub&quot;;
         URL url = new URL(sauceUrl);
         driver = new RemoteWebDriver(url, browserOptions);
         wait = new WebDriverWait(driver, Duration.ofSeconds(10));
  
  
  
      }
  
      @After
      public void tearDown(Scenario scenario) {driver.quit();}
  }
  </code></pre>
  <p><strong>PAGE OBJECT WHERE MY CODE IS:</strong> (shortened for privacy purposes)</p>
  <pre><code>public class LandingPO extends Hooks {
  
   static RemoteWebDriver driver;
   static WebDriverWait wait;
   String url = &quot;https://google.com&quot;
   public void openUrl() {
          driver.get(url);}
  </code></pre>
  <p>And then I just call this method (landingPO.openUrl();) in my stepDefinition class.
  The error is thrown where first driver usage is found:</p>
  <pre><code>Step failed
  java.lang.NullPointerException: Cannot invoke &quot;org.openqa.selenium.remote.RemoteWebDriver.get(String)&quot; because &quot;pageObjects.LandingPO.driver&quot; is null
  </code></pre>
  <p><strong>it breaks right at &quot;driver.get(url)&quot; in my LandingPO</strong></p>