getting error java: cannot find symbol symbol: method chrome() location: class Abstract.Abstract

282 Views Asked by At

I have started building up my first Selenium-Java automation project. I am getting error because not able to find chrome in code line DesiredCapabilities capabilities = DesiredCapabilities.chrome();

try {
                Map<String, String> mobileEmulation = new HashMap<String, String>();
                mobileEmulation.put("deviceName", deviceName);
                Map<String, Object> chromeOptions = new HashMap<String, Object>();
                chromeOptions.put("mobileEmulation", mobileEmulation);
                DesiredCapabilities capabilities = DesiredCapabilities.chrome();
                capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
                //System.setProperty("webdriver.chrome.driver", "C:/Users/user/path");
                driver.manage().window().maximize();
                driver.get(baseURL);
                MDC.put("BrowserName", "Responsive");
                MDC.put("DeviceName", deviceName);
                extent = new ExtentReports(
                        System.getProperty("user.dir") + "/test-output/ExtentReport.html", true);
                //extent.addSystemInfo("Host Name", "teststaf.mi4biz.net")
                extent.addSystemInfo("Host Name", "https://testsanem.mi4biztest.net/");
                       
                extent.loadConfig(new File(System.getProperty("user.dir") + "\\extent-config.xml"));
                inputStream = getClass().getClassLoader().getResourceAsStream("responsiveElement.properties");
            

Tries to find my method in here;

public class DesiredCapabilities extends MutableCapabilities {

  public DesiredCapabilities(String browser, String version, Platform platform) {
    setCapability(BROWSER_NAME, browser);
    setCapability(BROWSER_VERSION, version);
    setCapability(PLATFORM_NAME, platform);
  }

  public DesiredCapabilities() {
    // no-arg constructor
  }

  public DesiredCapabilities(Map<String, ?> rawMap) {
    if (rawMap == null) {
      return;
    }

    rawMap.forEach(this::setCapability);
  }

  public DesiredCapabilities(Capabilities other) {
    merge(other);
  }

  public DesiredCapabilities(Capabilities... others) {
    for (Capabilities caps : others) {
      merge(caps);
    }
  }

  public void setBrowserName(String browserName) {
    setCapability(BROWSER_NAME, browserName);
  }

  public void setVersion(String version) {
    setCapability(BROWSER_VERSION, version);
  }

  public void setPlatform(Platform platform) {
    setCapability(PLATFORM_NAME, platform);
  }

  public boolean acceptInsecureCerts() {
    if (getCapability(ACCEPT_INSECURE_CERTS) != null) {
      Object raw = getCapability(ACCEPT_INSECURE_CERTS);
      if (raw instanceof String) {
        return Boolean.parseBoolean((String) raw);
      } else if (raw instanceof Boolean) {
        return (Boolean) raw;
      }
    }
    return true;
  }

  public void setAcceptInsecureCerts(boolean acceptInsecureCerts) {
    setCapability(ACCEPT_INSECURE_CERTS, acceptInsecureCerts);
  }

I tried to change method chrome(), but it didn't worked. Should I edit DesiredCapabilities class. I was expecting to rename the method with something valuable and able to find symbol.

1

There are 1 best solutions below

1
gross21 On

I changed my code block like below and it is fixed. Thank you.

Map<String, String> mobileEmulation = new HashMap<String, String>();
            mobileEmulation.put("deviceName", deviceName);
            Map<String, Object> chromeOptions = new HashMap<String, Object>();
            chromeOptions.put("mobileEmulation", mobileEmulation);
            DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
            capabilities.setCapability("chromeVersion", "118.0");

            System.setProperty("webdriver.chrome.driver", "C:/Users/path");
            driver.manage().window().maximize();
            driver.get(baseURL);
            MDC.put("BrowserName", "Responsive");
            MDC.put("DeviceName", deviceName);
            extent = new ExtentReports(
                    System.getProperty("user.dir") + "/test-output/ExtentReport.html", true);
            extent.loadConfig(new File(System.getProperty("user.dir") + "\\extent-config.xml"));
            inputStream = getClass().getClassLoader().getResourceAsStream("responsiveElement.properties");