Page tree
Skip to end of metadata
Go to start of metadata

Last updated: Dec 31, 2018 11:18

For automation testing where you don't need a visible UI shell.

Setup 

  1. Run Perfecto wizard from ide to create project.
  2. Add the following code to main

    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");

    Optional: Capture Screenshots to show what pages were visited.

    // 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();

     Check Execution report to see that Chrome was running in Headless Mode.

Google - Getting started with Headless Chrome

The power of Headless Chrome and browser automation (Google I/O '18)