when I'm running my automation tests,I keep getting the "Disable Developer Mode Extension" in mobile emulation,I am using Chrome 2.21 driver - selenium

Here is the Sample code:
System.setProperty("webdriver.chrome.driver", "C:\\Selenium\\chromedriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
//this line of code added to disable extension but still getting the alert capabilities.setCapability("chrome.switches", Arrays.asList("--disable-extensions"));
WebDriver driver = new ChromeDriver(capabilities);
How to disable this extension alert in mobile emulation mode?
If I add the below code,mobile emulation is not showing:
ChromeOptions options= new ChromeOptions();
options.addArguments("--disable-extensions");
How to disable this alert in mobile emulation mode using Selenium webdriver?

Try this...
ChromeOptions chop = new ChromeOptions();
chop.addArguments("--disable-extensions");
WebDriver driver = new ChromeDriver(chop);

Related

Is there a way to set Chrome extension settings using selenium?

I am able to place extension using crx file. However, I need to change some setting in Chrome extension using selenium. Is there any chrome API or somehow I can automate this part. Appreciate!
When you instantiate the ChromeDriver, try using the below code:
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("/path/to/extension.crx"));
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
ChromeDriver driver = new ChromeDriver(capabilities);

How to Set capability for IE browser to run in Headless mode

I want to run the scripts in Headless mode for all the 3 browsers Chrome, Firefox & IE
The following is the code for Chrome:
System.setProperty("webdriver.chrome.driver", "./drive/chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("headless");
options.addArguments("window-size=1400,600");
WebDriver driver = new ChromeDriver(options);
driver.get("http://www.google.com/");
Note : Its working fine
Firefox:
FirefoxBinary firefoxBinary = new FirefoxBinary();
firefoxBinary.addCommandLineOptions("--headless");
System.setProperty("webdriver.gecko.driver", "./drive/geckodriver.exe");
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setBinary(firefoxBinary);
FirefoxDriver driver = new FirefoxDriver(firefoxOptions);
driver.get("http://www.google.com/");
Note : Its working fine
IE:
Similarly i want to execute in IE with options
IE does not have support for a headless mode (since IE nowadays does not recieve any kind of update or improvements.).
But you can use trifle.js, a kind of browser that can emulate some IE versions in a headless mode, since its coded as a port of PhantomJS.

Unable to find element on new tab link

When I run a browser with extension a pop up arise that says "Disable developer mode" to do so my script clicks on Disable, it opens a new tab with url "chrome://extensions/"
Now to click on checkbox of developer mode it always give an error "Unable to locate element."
driver.findelement(By.id("toggle-dev-on"));
http://prntscr.com/f8fbde
Here is the solution for your Question:
As per best practices to work with Selenium 3.4.0 you must download the latest chromedriver v2.29 from here, update your Google Chrome to 58.x.
Updating your chromedriver to v2.29 will solve your issue of Disable developer mode
To work with Google Chrome you can take help of ChromeOptions Class as follows:
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
options.addArguments("disable-infobars");
options.addArguments("--disable-extensions");
WebDriver driver = new ChromeDriver(options);
driver.get("https://gmail.com");
Let me know if this solves your Question.
You need to modify the appropriate browser profile to have JS disabled. Like for FireFox/Chrome you can tell Selenium which profile to use.
Chrome :
Map prefs = new HashMap();
prefs.put("profile.default_content_setting_values.notifications", 2);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", prefs);
WebDriver driver = new ChromeDriver(options);
FireFox :
FirefoxProfile ffprofile = new FirefoxProfile();
ffprofile.setPreference("dom.webnotifications.enabled", false);
WebDriver driver = new FirefoxDriver(ffprofile);
Hope this will work out for your case.

How to maximise the window in chrome browser in incognito mode using Selenium WebDriver?

How to maximise the window in chrome browser in incognito mode using Selenium WebDriver
I am using the below code:
ChromeOptions options = new ChromeOptions();
options.addArguments("--incognito");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(capabilities);
driver.manage().window().maximize();
But in the last line code I am getting error as Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: No current window
To maximize the Chrome Browser in incognito mode you need to use the ChromeOptions class as follows:
ChromeOptions options = new ChromeOptions();
options.addArguments("--incognito");
options.addArguments("start-maximized");
WebDriver driver = new ChromeDriver(options);

Browser Plugin Testing With Selenium

I am writing a webapp that has a browser plugin component for both firefox and chrome. My current testing system uses a series of Selenium tests created through Selenium IDE.
Is it possible to also have selenium install, activate, and delete browser plugins for firefox and chrome (possibly other browsers as well)?
I think the biggest concern is that installing/enabling the browser plugin requires a browser restart, and I'm not sure if that would through selenium off.
The acquisition of the plugin is easily handled by visiting an internal site-link to a php-script that detects your browser.
The answer is Yes, Selenium 2 supports (remote) installation of browser extensions.
The Chrome and Firefox WebDriver support the installation of extensions, remotely. Here's sample code for Chrome and Firefox:
Chrome
File file = new File("extension.crx"); // zip files are also accepted
ChromeOptions options = new ChromeOptions();
options.addExtensions(file);
// Option 1: Locally.
WebDriver driver = new ChromeDriver(options);
// Option 2: Remotely
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
Firefox
File file = new File("extension.xpi");
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.addExtension(file);
// Option 1: Locally
WebDriver driver = new FirefoxDriver(firefoxProfile);
// Option 2: Remotely
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.PROFILE, firefoxProfile);
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
I have also implemented automated installation of Opera and Safari extensions, and they have been merged upstream:
OperaDriver: https://github.com/operasoftware/operadriver/pull/93
SafariDriver: https://github.com/SeleniumHQ/selenium/pull/87
Opera
This API is similar to the FirefoxDriver.
File file = new File("extension.oex"); // Must end with ".oex"
OperaProfile operaProfile = new OperaProfile();
operaProfile.addExtension(file);
// Option 1: Locally
WebDriver driver = new OperaDriver(operaProfile);
// Option 2: Remotely
DesiredCapabilities capabilities = DesiredCapabilities.opera();
capabilities.setCapability("opera.profile", operaProfile);
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
Safari
This API is similar to the ChromeDriver.
File file = new File("extension.safariextz");
SafariOptions options = new SafariOptions();
options.addExtensions(file);
// Option 1: Locally.
WebDriver driver = new SafariDriver(options);
// Option 2: Remotely
DesiredCapabilities capabilities = DesiredCapabilities.safari();
capabilities.setCapability(SafariOptions.CAPABILITY, options);
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
Internet Explorer
Good luck.
Short answer: no
Installing a browser extension is outside of the scope of handling in Selenium.
In Chrome, it displays a modal window that is not "clickable" with Selenium when you want to add a plugin or app. Chrome does not require restarting.
Firefox has the same kind of behaviour to prompt for extension permissions.
You can try something that resides outside of the browser to do what you want. Sikuli might do the trick.