I am having hard time maximizing chrome browser using theintern/leadfoot command
maximize.
I tried maximize window .maximizeWindow() (it works for firefox but not for chrome browser. I even tried execute("window.resizeTo(14400, 8130);")
and setWindowSize("", 1440, 813);
Has any one tried a different approach?
You can add Chrome commandline argument --start-maximized, you can pass it in chromeOptions
{
browserName: 'chrome',
chromeOptions: {
args: [
'start-maximized'
]
}
}
Related
I want to ask how to open the Chrome developer Console during selenium tests execution. Currently, when tests are executing, and I open the console manually hitting F12, the tests stop responding immediately and fails after some time.
Can anyone tell me how can I initiate my tests with developer console opened, so I can catch/observe the console errors that occur during test execution.
Use --auto-open-devtools-for-tabs:
This flag makes Chrome auto-open DevTools window for each tab. It is intended to be used by developers and automation to not require user interaction for opening DevTools.
Source
How to use
Note: this answer does not apply to current versions of Chrome.
You can't. The Chrome driver uses the Chrome remote debugging protocol to communicate with the browser. This is the same protocol that the developer console uses also. Unfortunately, Chrome is designed so that only one client can be attached using the protocol at a time, so that means either the developer tools, or the driver, but not both simultaneously.
Have you tried simulating the key press events for the shortcut of opening the dev tools in Chrome?
String openDevTools = Keys.chord(Keys.ALT, Keys.CONTROL, "i");
driver.findElement(By.ByTagName("body")).sendKeys(openDevTools);
This is not ideal and in a rigorous testing regime you would need platform detection to ensure you are covering both Mac and Windows. I would absolutely recommend avoiding this (even if it works), but it's a possible as a work-around if you really must.
I have a feeling it may also lose focus of the window itself if you do this. If this is the case, you'd need something like the following: -
String parentHandle = driver.getWindowHandle(); // get the current window handle
// do your dev tool stuff here
driver.switchTo().window(parentHandle); // switch back to the original window
Hope this helps.
Useful link if it does get you anywhere: How to handle the new window in Selenium WebDriver using Java?
Edit: Just re-read the question and don't think this will work anyway. Your unit tests should capture errors in the logic of your code. Your selenium tests should only test user journeys and capture errors when the user journey is cut short. You should never be testing code logic/error throwing through a selenium test.
This is working for me in webdriver.io (wdio.conf.js)
const configs = {
chrome : {
maxInstances: "5",
browserName: "chrome",
chromeOptions: {
args: ['--window-size=1280,800', '--auto-open-devtools-for-tabs'],
binary: '/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome'
}
},
firefox : {
maxInstances: "5",
browserName: "firefox"
},
headless : {
maxInstances: "5",
browserName: "chrome",
chromeOptions: {
args: ['--headless', '--disable-gpu', '--window-size=1280,800'],
binary: '/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome'
}
},
}
Is there a way in WebdriverIO framework to launch the browser with JavaScript disabled?
I want to automate a scenario with JavaScript being disabled. But, when I manually disable the JavaScript in Chrome, or Firefox and run the WDIO scripts, the browser always opens with JavaScript enabled.
Not anymore. (but you have a workaround below)
This used to be easily achieved using the chromium switches. But considering all driver implementations (chromedriver, geckodriver, etc.) now require JavaScript to drive your spawned browser instance, it's no longer possible.
It was achieved via chromeOptions arguments/switches:
capabilities: [{
maxInstances: 2,
browserName: config[env].browser,
chromeOptions: {
args: ['--disable-javascript',
'--disable-javascript-harmony-shipping'
]
}
}]
!!! LATER EDIT: You can achieve this by loading a custom profile.
Start your WebdriverIO test case, but add a browser.debug() after you load your page;
In the address bar, type chrome://settings/content and in the modal, check the Do not allow any site to run JavaScript. Click Done. Now go to a random page and notice JavaScript has been blocked on it:
Now we have to save this custom profile and load it each time you start a WebdriverIO test case. Type chrome://version in your address bar. Notice the Profile Path value. Copy the content of the folder (e.g.: For C:\Users\<yourUserName>\Desktop\scoped_dir18256_17319\Default, copy the scoped_dir18256_17319 folder on your Desktop). This folder contains all the actions (search history, extensions installed, accounts saved... in our case, JavaScript disabled option) on THIS current instance.
Now all we need to do, is add the path to that folder in your wdio.config.js file as a chromeOptions argument:
chromeOptions: {
//extensions: ['./browserPlugins/Avira-SafeSearch-Plus_v1.5.1.crx'],
args: [ '--user-data-dir=/Users/<yourUserName>/Desktop/scoped_dir18256_17319'
]
}
Now all you have to do is run your test cases with this custom profile and JavaScript will be blocked on all websites. Hope this is the behavior you are looking for as there is no other way to achieve this behavior.
Cheers!
I'm running my protractor tests with Chrome and i'd like to run them with Firefox too. Problem is I can't find how to enable CORS in firefox like I do in Chrome.
This is my configuration for Chrome:
capabilities:{
'browserName': 'chrome',
'chromeOptions': {
'args': ['--disable-web-security']
}
},
Hate to say it but FireFox doesn't have similar functionality.
In fact, out of the main four browsers (Chrome, Safari, FF and IE), only Chrome and IE will allow you to run with web security disabled and only Chrome from the command line.
Source: I spent a lot of time looking for a way to run each of these browsers with CORS security disabled and failed on all accounts except for Chrome and IE.
with selenium webdriverjs we can use this
npm : https://github.com/saadtazi/firefox-profile-js
var FirefoxProfile = require('firefox-profile'),
webdriverjs = require('webdriverjs');
var fp = new FirefoxProfile();
fp.setPreference("security.fileuri.strict_origin_policy", false);
And this is the link to set specific firefox profile for Protractor
https://github.com/juliemr/protractor-demo/tree/master/howtos/setFirefoxProfile
I'm creating an application that can be run both in kiosk mode and normally (like, open from Chrome browser) but certain features should only be allowed to run in kiosk mode. Is there a way I can find out if it's running in kiosk-mode or in normal fullscreen/windowed-mode?
Here's a snippet from my manifest.json if it's any help
{
"manifest_version": 2,
"kiosk_enabled": true,
"kiosk_only": false
}
From the documentation:
To determine whether the app is being run in a regular session or Single App Kiosk Mode, you can inspect the isKioskSession boolean that's included in the launchData object from the app.runtime.onLaunched event.
So:
chrome.app.runtime.onLaunched.addListener(function(launchData) {
launchData.isKioskSession; //true or false
});
i am writing a text editor, i need the app window be always on top when switching to browser or e-book reader software. as i know ,for windows users, chrome doesn't provide any solution. is there any parameter to send when creating window to make window always on top?
or can i provide any button in app to turn this feature on or off?
Code i use to create window in bg.js:
var launch = function () {
chrome.app.window.create('index.html', {
type: 'shell',
width: 440,
height: 680,
minWidth: 440,
maxHeight: 680,
id: 'paat-start'
});
};
chrome.app.runtime.onLaunched.addListener(launch);
chrome.commands.onCommand.addListener(launch);
thank for any suggestion.
As Ben Wells mentioned above, this feature is now available in the stable release (either v33 or v34) via the alwaysOnTop option in chrome.app.windows.create. Note that special permissions are required in the manifest.json file. Example:
background.js
chrome.app.window.create('window.html', {
alwaysOnTop: true,
}, function (appWindow) {
// Window created and will remain on top of others.
// Change the property programmatically via:
//appWindow.setAlwaysOnTop();
});
manifest.json
"permissions": [
"alwaysOnTopWindows"
]
This seems to have been added in issue 26427002, gone stable in issue 159523002 and issue 48113024 thanks to the community!
I had looked into this a while back and wanted to catalog my findings since historically there were some discrepancies in the documentation which previously stated the name of the required permission was alwaysOnTop, but using this caused a "permission is unknown" error.
Reading through the original proposal for this feature lead me to issue 326361 which mentions the permission setting is actually called alwaysOnTopWindows. Using this one back then, however, yielded a "requires Google Chrome dev channel or newer" error (probably since the feature wasn't yet stable).
I did find it peculiar from browsing the source code, these two permissions might be aliases of each other, but that might be because I don't fully understand the Chromium codebase.
chrome.app.window.create does support a boolean alwaysOnTop option in more recent versions of Chrome. The feature is currently in beta channel on most platforms and at least dev channel on the rest.