intellij 2017.2 System.setProperty' class'或者'界面'预期

时间:2017-07-21 15:05:50

标签: java selenium intellij-idea

我在WebDriver测试中有一个典型的类用于启动webbrowsers。我使用IntelliJ,自2017.2版以来,它强调(红线):" webdriver.gecko.driver"或" webdriver.chrome.driver",并附有解释:' class'或者'界面'预期。 你能告诉我为什么吗?

我的课程包含:

package com.qa.commonhelper;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.util.concurrent.TimeUnit;

public class BrowserFactory {

    public static WebDriver driver;

    public static WebDriver startBrowser(String browserName, String url) {
        if (browserName.equals ("firefox") && osDetector ().equals ("Linux")) {
            System.setProperty ("webdriver.gecko.driver", "src/test/resources/drivers/geckodriver");
            DesiredCapabilities capabilities = DesiredCapabilities.firefox();
            capabilities.setCapability("marionette", false);
            driver = new FirefoxDriver();
        } else if (browserName.equals ("chrome") && osDetector ().equals ("Linux")) {
            System.setProperty ("webdriver.chrome.driver", "src/test/resources/drivers/chromedriver");
            driver = new ChromeDriver ();
        } else if (browserName.equals ("firefox") && osDetector ().equals ("Windows")) {
            System.setProperty("webdriver.gecko.driver", "src/test/resources/drivers/geckodriver.exe");
            DesiredCapabilities capabilities = DesiredCapabilities.firefox();
            capabilities.setCapability("marionette", false);
            driver = new FirefoxDriver();
        } else if (browserName.equals ("chrome") && osDetector ().equals ("Windows")) {
            System.setProperty ("webdriver.chrome.driver", "src/test/resources/drivers/chromedriver.exe");
            driver = new ChromeDriver ();
        }
        driver.get (url);
        driver.manage ().window ().maximize ();
        driver.manage ().timeouts ().implicitlyWait (6, TimeUnit.SECONDS);
        return BrowserFactory.driver;
    }

    public static String osDetector () {
        String os = System.getProperty("os.name").toLowerCase();
        if (os.contains("win")) {
            return "Windows";
        } else if (os.contains("nux") || os.contains("nix")) {
            return "Linux";
        } else {
            return "Other";
        }
    }
}

0 个答案:

没有答案