webdriver无法启动浏览器

时间:2019-06-10 14:42:56

标签: java nullpointerexception webdriver

我用pagefactory设置了简单的注册码。当我尝试运行时,如果出现以下错误:

  

java.lang.NullPointerException       在org.openqa.selenium.support.pagefactory.DefaultElementLocator.findElement(DefaultElementLocator.java:69)       在org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:38)       在PageFactoryRivision.Utils.clickOnElement(Utils.java:25)       在PageFactoryRivision.RegistrationPage.Registration(RegistrationPage.java:77)       在PageFactoryRivision.TestSuits.Register(TestSuits.java:23)

public class _DriverManager {

    protected static WebDriver driver;

    public _DriverManager(){
        PageFactory.initElements(driver, this);
    }

    public static void openBrowser(){
        String browser = "";
        if (browser.equalsIgnoreCase("chrome")){
            System.setProperty("webdriver.chrome.driver","src\\test\\Resorces\\BrowsDrivers\\chromedriver.exe");
            driver = new ChromeDriver();
        }
        else if (browser.equalsIgnoreCase("ie")){
            System.setProperty("webdriver.ie.driver", "src\\test\\Resorces\\BrowsDrivers\\IEDriverServer.exe");
            driver = new InternetExplorerDriver();
        }
        else {
            System.setProperty("webdriver.gecko.driver", "src\\test\\Resorces\\BrowsDrivers\\geckodriver.exe");
            driver = new FirefoxDriver();
        }

        driver.get("http://www.gmaail.com");
        driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
        driver.manage().window().maximize();
    }

    public static void closeBrower(){
        driver.manage().deleteAllCookies();
        driver.quit();
    }
}





public class TestSuits extends _DriverManager {

    @BeforeTest
    public void open() {
        _DriverManager.openBrowser();
    }

    @AfterTest
    public void close() {
        _DriverManager.closeBrower();
    }

    @Test
    public void Register(){
        RegistrationPage registrationPage = new RegistrationPage();
        registrationPage.Registration();
    }
}

它应该打开网站并成功注册,但首先不打开浏览器。我不明白为什么。

0 个答案:

没有答案