Session.desiredCapabilities are ignored by Session.negotiatedCapabilities when running PhantomJSDriver
Asked Answered
S

0

1

I have a requirement where I need to run test scenarios of validating my webpage in Amazon linux2 instance without any GUI. Hence I selected PhantomJS/GhostDriver to perform these executions. I also need to add valid certificate in my driver for running tests.

Part of the code when setting Desired capabilities and initiating my PhantomJS driver.

capabilities = new DesiredCapabilities();
        capabilities.setJavascriptEnabled(true);
        capabilities.setAcceptInsecureCerts(true);
        capabilities.setCapability("takesScreenshot", true);
        capabilities.setCapability("browserName", "phantomjs");
        try {
            final String webSecurity = "--web-security=false";
            final String sslProtocol = "--ssl-protocol=any";
            final String ignoreSSLErrors = "--ignore-ssl-errors=true";
            final String webDriverLogLevel = "--webdriver-loglevel=DEBUG";
            final String clientCertFile = "--ssl-client-certificate-file=" + clientCertificateAbsolutePath;
            final String clientKeyFile = "--ssl-client-key-file=" + clientSecretKeyAbsolutePath;
            final String clientKeyPassphrase = "--ssl-client-key-passphrase=" + passPhrase;
            String[] params = new String[]{webSecurity, sslProtocol, ignoreSSLErrors, webDriverLogLevel, clientCertFile, clientKeyFile, clientKeyPassphrase};
            String phantomJSPath = System.getProperty("user.dir");
            logger.info("Path for PhantomJS file:" + phantomJSPath);              capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,  "/usr/bin/phantomjs");
            capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS,params);
            WebDriver driver = new PhantomJSDriver(capabilities);

When test is being executed, I am noticing that desiredCapabilities are being ignored and replaced by negotiatedCapabilities and hence the Cert details are being invalidated when headless browser is rendered. enter image description here

Can anyone please suggest how it can be resolved or any better way or approach for running my tests.

Subcelestial answered 18/3, 2022 at 16:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.