I am trying to programmatically set default download location for my testcafe tests. Is there is an option to pass a command-line argument to change default download location while executing tests in chrome in headless mode?
TestCafe doesn't have a CLI or a programmatic option for changing the browser's download behavior and Сhrome doesn't have such a flag. To achieve this, you need to use the setDownloadBehavior DevTools Protocol's function in the following way:
await t.testRun.browserConnection.provider.plugin.openedBrowsers[t.testRun.browserConnection.id].client.Page.setDownloadBehavior({ behavior: 'allow, downloadPath: '...' });
To test file download you can use the RequestLogger feature instead of setting the default download directory. See the check-downloaded-file-name-and-content example for more information.
Related
I am trying to test around a webcam using fake stream, however, there is a check to see if the camera settings is allowed before it can work.
I am working with testcafe and my code is similar to what is below which doesn't work for the args (unless without the profile).
Using --use-fake-ui-for-media-stream and --use-file-for-fake-video-capture works for stream, however the check for camera settings still fails. I tried using a user profile which works for the camera settings but not the chrome arguments. Does anyone know how I can combine these two to work ?
chrome:userProfile --start-fullscreen --allow-insecure-localhost --use-fake-device-for-media-stream --use-fake-ui-for-media-stream --use-file-for-fake-video-capture="/path/to/video.y4m" ')
Chrome can't apply CLI flags without creating a new browser instance and can't create a new browser instance if you have other Chrome instances that use the same profile.
If you want to use "chrome:userProfile" together with CLI flags, you can close all Chrome processes on your machine. Or you can create a dedicated directory for a temporary Chrome profile and use it in tests by specifying chrome --user-data-dir=$TEMP_PROFILE_DIRECTORY as a browser.
I'm working on Chrome with Selenium and I'm looking to change a few settings within Chrome using the webdriver. Using Google and this site, I was able to get most of the settings working. However, a few more seem to escape me and hopefully I can get the answers here. I'm looking to alter the settings before launching the browser, such as using ChromeOptions, rather than using automation to navigate the settings page.
The settings I'm looking to change are as follows:
Disable Javascript
Disable the microphone
Change the home page
Altering the default search engine in the Omnibox
These 4 are giving me the most issues. Any help?
Perhaps this List of Chromium Command Line Switches will help. E.g.
DesiredCapabilities caps = DesiredCapabilities.chrome();
caps.setCapability("chrome.switches", Arrays.asList("--disable-javascript"));
And
Map<String, Object> preferences = Maps.newHashMap();
preferences.put( "browser.startup.homepage", "http://my.home.page" );
preferences.put( "browser.startup.page", START_WITH_HOME_PAGE );
capabilities.setCapability( ChromeOptions.CAPABILITY, preferences );
ChromeDriver driver = new ChromeDriver( capabilities );
Update
My guess is that the following
"import_search_engine": true
from Configuring other parameters will cause Chrome to ask you to select a search engine when it opens.
Turning off JavaScript makes chrome pretty much a no-op; I do not think that the option is supported. As far as microphones, that is more a system option. A search of about:config for microphone came up empty.
I'd like to be able to send info to the Chrome developer console from my application.
For example, my app has some json. I'd like this json to show up in either an existing, or newly created instance of the chrome dev tools console.
Is this possible? If so, any pointers to examples? Note that the platform should be any language, not just javascript. And definitely not a site already running in Chrome. I'm interested in implementing this in another process.
Do you thought of running your app in an environment which is pretty much like a browser?
Node.js
or (this is a whole webkit browser)
phantom.js
Otherwise you could call Chrome directly via commandline and try to simulate the dev tools key stroke like explained here:
Is there a command line argument in Chrome to start the developer tools on startup?
The command of displaying something in the Chrome console is e.g. console.log and it is at the end Javascript. All Console commands are described here:
https://developers.google.com/chrome-developer-tools/docs/console-api
The closest I've seen so far is this library:
https://github.com/ccampbell/chromelogger
which seems to allow logging to the Chrome Console from lots of other server side apis, but no desktop APIs.
This can be done on Mac using osascript. Save the following as a script and run it:
#!/usr/bin/osascript -l JavaScript
var chrome = Application('Google Chrome');
//chrome.activate();
chrome.includeStandardAdditions = true;
var currentTab = chrome.windows[0].activeTab()
currentTab.execute({javascript: 'console.log("Hello")'})
How do I access the results array from the following page using Google Chrome's console?
twitter.com/search.json?q=stackexchange
I keep getting this error:
ReferenceError: results is not defined
If what you really want is to browse this result set in a convinient way, just install one of JSON viewers for Chrome (preferably JSONView).
If you don't want to install any plugins, just run this:
JSON.parse($('.webkit-line-content').innerHTML);
in the console on page:
view-source:https://search.twitter.com/search.json?q=stackexchange
You can use console.debug() function in chrome console tab.
example:
console.debug(results)
Does testcafe support to load crx extensions in Chrome browser?
If so, please let me know what method needs to try out.
I tried below the code it doesn’t work out
await t.eval(new Function(fs.readFileSync('/foo.crx').toString()));
And also testcafe support to setup ModHeader extension with the custom header values.
Chrome extension file is an archive, which can contain not only .js files, but also .html, .css and any other file types. This means that it is not possible to install an extension via the t.eval function which executes JavaScript code.
If you only need to execute some js code from the extension, you can extract your crx file using the https://crxextractor.com/ service and call the eval function for the unpacked .js file.
As I understand, you want to use the ModHeader extension for intercepting HTTP requests, modify header values and so on. If so, please take a look at the built-in Request Hooks functionality which allows you to accomplish this task.