Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can we disable web security of chrome browser using selenium/TestNg [duplicate]

I want to use the following command using selenium/testng inside my code since every-time I execute the code, a new instance of browser is created by webdriver in which security is enabled by default.

chrome.exe --disable-web-security
like image 405
SHARAN Avatar asked Oct 08 '15 10:10

SHARAN


People also ask

Is it possible to do security testing with selenium?

I have come across many articles which talk of carrying out security testing with selenium however I found it very cumbersome to set up such tests. This is what this tutorial is going to make easy for you.

How to handle SSL certificate in Selenium WebDriver?

For the Chrome browser, one can handle the SSL certificates using ChromeOptions class provided by Selenium WebDriver. It is a class that we can use to set properties for the Chrome browser.

How to enable JavaScript in selenium with automation testing?

Launch a browser and enter “about:config” in URL address bar Double click on “javascript.enabled” available entry to set boolean value as false Note: You can use this website for confirming if your JavaScript is enabled or disabled. Now, we get down to automation testing with Selenium.

How to disable the security checks in chrome?

Only one thing left, disabling the security checks entirely! To do this you can start another instance of Chrome from your terminal using the --disable-web-security and --ignore-certificate-errors flags.


1 Answers

Try something this, Change the path and slashing accoding to your specifications :-

            WebDriver driver=null;
            System.setProperty("webdriver.chrome.driver","./src//lib//chromedriver");
            DesiredCapabilities capabilities = DesiredCapabilities.chrome();
            ChromeOptions options = new ChromeOptions();
            options.addArguments("test-type");
            options.addArgument("--start-maximized");
            options.addArguments("--disable-web-security");
            options.addArguments("--allow-running-insecure-content");
            capabilities.setCapability("chrome.binary","./src//lib//chromedriver");
            capabilities.setCapability(ChromeOptions.CAPABILITY, options);
            driver = new ChromeDriver(capabilities);
            driver.get("https://www.google.com/");

Below is the link where all available chrome flags are listed :-

http://peter.sh/experiments/chromium-command-line-switches/

Hope it will help you :)

like image 120
Shubham Jain Avatar answered Sep 17 '22 23:09

Shubham Jain