I have 2 classes belonging to the same package in a java testNG project and I have declared 'webdriver driver' public static in class A. In that class, chrome launched, url opened, username and password were entered and login button clicked. Worked fine using @BeforeClass annotation.
I copied the same code into a class B and changed browser instance to firefox whilst still declaring 'webdriver driver as public static. Firefox Launched, URL opened, username and password were entered but login button did not click or submit. Test failed with the error:
org.openqa.selenium.JavascriptException: Error: Unable to find owning document.
I have never come across this error and have no idea what 'owning document' is being referred to.I am suspecting it has something to do with the access level for either or both classes. Below is an extract from the 2 classes. Am I missing something?
*
package com.example;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class TheChrome {
public static WebDriver driver;
@BeforeClass(alwaysRun = true)
public void launchBrowser() {
driver = new ChromeDriver();
driver.get("http://www.example.com");
driver.manage().window().maximize();
@Test
public void verifyLogin() throws InterruptedException {
driver.findElement(By.id("username")).sendKeys("user");
driver.findElement(By.id("password")).sendKeys("password");
Thread.sleep(3000);
driver.findElement(By.id("loginButton")).click();
*
package com.example;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class TheFirefox {
public static WebDriver driver;
@BeforeClass(alwaysRun = true)
public void launchBrowser() throws InterruptedException {
driver = new FirefoxDriver();
driver.get("http://www.example.com");
driver.manage().window().maximize();
Thread.sleep(3000);
}
@Test
public void verifyLogin() throws InterruptedException {
driver.findElement(By.id("username")).sendKeys("user");
driver.findElement(By.id("password")).sendKeys("password");
Thread.sleep(3000);
driver.findElement(By.id("loginButton")).click();