Search code examples
javaseleniumselenium-webdriverphantomjsheadless

Unecessary logs in headless testing using phantom js and selenium


I am getting so many unnecessary logs in red color while performing headless testing using phantom js.

How to remove all those red color logs red colour info messages

public class Utility 
{
   private static WebDriver driver=new PhantomJSDriver();
   public static WebDriver getDriver() 
   {
      return driver;
   }
}    

Solution

  • Here is what you need to do to suppress the INFO logs:

    File src = new File("C:\\Utility\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe");
    System.setProperty("phantomjs.binary.path", src.getAbsolutePath());
    
    DesiredCapabilities dcap = new DesiredCapabilities();
    String[] phantomArgs = new  String[] {
        "--webdriver-loglevel=NONE"
    };
    dcap.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, phantomArgs);
    PhantomJSDriver driver = new PhantomJSDriver(dcap);
    
    driver.get("https://www.facebook.com/");
    

    Let me know if it works for you.