如何在测试中实现设置属性


    import org.testng.annotations.*;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class redc {
    public static WebDriver driver=null;
    public static  void startdriver()
    {
    String key="webdriver.gecko.driver";
    String path="C:\selenium3\geckodriver\geckodriver.exe";
    System.setProperty(key,path);
    driver = new FirefoxDriver();
        }
    @BeforeMethod
    public void call()
    {

    }
    @Test
    public void t1()
    {
        driver.get("https://www.dynamiclevels.com/");
    }

我正在尝试运行此代码,但不断出现错误

FAILED: t1 java.lang.NullPointerException at datac.redc.t1(redc.java:25) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

请帮我更正代码。如果可能的话,以它能工作的方式重写它。我确信我犯了同样无法抓住的愚蠢错误。:(

@BeforeTest
public void setup() {
    String key= "webdriver.gecko.driver";
    String path= "C:\selenium3\geckodriver\geckodriver.exe";
    System.setProperty(key, path);
    driver = new FirefoxDriver();
}

并从网络驱动程序中删除静态:

private WebDriver driver;

最新更新