Set up headless Chrome in a Perfecto environment
This is helpful for automation testing (where you do not need a visible UI shell).
To set up headless Chrome:
- Run the Perfecto wizard from the IDE to create a project.
-
Add the following code to main:
Copypublic 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) 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(); -
Check the single test report to see that Chrome was running in Headless mode.
External links
Related Articles
See also the Perfecto Knowledgebase.