Set up headless Chrome in a Perfecto environment

This is helpful for automation testing (where you do not need a visible UI shell).

Setup 

  1. Run the Perfecto wizard from the IDE to create a project.
  2. Add the following code to main:

    Copy
    public static void main(String[] args) throws IOException {
        System.out.println("Run started");

        String host = "[cloud].perfectomobile.com";

        ChromeOptions chromeOptions = new ChromeOptions();
        //chromeOptions.addArguments("--headless");
        chromeOptions.setHeadless(true);
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
        capabilities.setCapability("securityToken", "[replace with securityToken]");
        capabilities.setCapability("platformName", "Windows");
        capabilities.setCapability("platformVersion", "10");
        capabilities.setCapability("browserName", "Chrome");
        capabilities.setCapability("browserVersion", "latest");
        capabilities.setCapability("location", "US East");
  3. Optional: Take screen shots to show what pages were visited.

    Copy
    // write your code here
    reportiumClient.stepStart("Goto CNN");
    driver.get("http://cnn.com");
    File file = driver.getScreenshotAs(OutputType.FILE);
    FileUtils.copyFile(file,new File("ScreenShot-cnn.jpg"));
    reportiumClient.stepEnd();
    reportiumClient.stepStart("Goto Google News");
    driver.get("http://news.google.com");
    file = driver.getScreenshotAs(OutputType.FILE);
    FileUtils.copyFile(file,new File("ScreenShot-googlenews.jpg"));
    reportiumClient.stepEnd();
  4. Check the single test report to see that Chrome was running in Headless mode.

See also the Perfecto Knowledgebase.