Forum Discussion

RichardPla's avatar
RichardPla
Occasional Contributor
10 months ago

Setting browser options programmatical

Why I cannot set browser options (e.g. chrome) using this javascript code:'

 

Browsers.Item("chrome").RunOptions = '--incognito';
Browsers.Item("chrome").RunOptions = '--headless';

 

Tried using this code:

 

var browserOptions = {
                                            'args': [
                                                          '--headless',
                                                         '--incognito'
                                                       ]
};

 

in conjunction w this code:

 

Browsers.RemoteItem(server, browserOptions ).Run();

 

Still no joy - am I trying something that is impossible?...

 

Regards,

 

/Richard

2 Replies

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    In JavaScript it's,

     

    Browsers.Item(btChrome).RunOptions = "-incognito"
    or
    Browsers.Item(btEdge).RunOptions = "-inprivate"

     

     

    • RichardPla's avatar
      RichardPla
      Occasional Contributor

      Thanks, but you reply is not sufficient.

       

      1. 1. You might want to consider updating you documentation with that info as it is not immediately obvious that specifying Chrome options requires just one hyphen (“-“) instead of “—”, which is a standard (see  https://peter.sh/experiments/chromium-command-line-switches/ )that you follow in you documentation on page https://support.smartbear.com/testcomplete/docs/app-testing/web/general/preparing-browsers/chrome.htmld in paragraph “Command-line arguments”.
      2.  
      3. 2. You did NOT address the headless mode of browser operation, which happens to be far more important to my organization. This line of code:

      Browsers.Item(btChrome).RunOptions = '-incognito';

       

      does not alter the behavior of the browser, which still shows full UI after starting.

       

      I have tried (rightly or wrongly) an alternative approach based on you documentation (https://support.smartbear.com/testcomplete/docs/app-testing/web/supported-browsers/headless.html ). Here, again, is my code:

        var url = "https://msdn.microsoft.com/";

        var capabilities = {

                              "browserName": "chrome",

                              "goog:chromeOptions": {

                                                                "args": [

                                                                               "-headless",

                                                                               "-incognito"

                                                                        ]

                                                    }

                             };

                            

        Browsers.RemoteItem(“localhost”, capabilities).Run(url);

       

       When executed it terminates with this error:

       

       even though the latest version of chromedriver is present in “C:\ProgramData\SmartBear\WebDrivers\chrome” folder (as per your documentation – “<ProgramData>\SmartBear\WebDrivers\<browser> “).

       

      Can you please either tell me what am I doing wrong when specifying “headless” mode as  a simple run option, or explain what is wrong with my code related to the Browser.RemoteItem command.