I have write a few browser test who run with TestCafe, chrome:headless. The test are launched by commandline, from a server that I don't want to change the default language.
My website is multi-language. I want to be change the language of the test, without having to impact the language of the server/computer each time. How can I do that?
I launch the tests with this command line:
npx testcafe chrome:headless src/scenarios/**/*.test.ts
It all depends on your "multi-language" implementation:
Navigate to some "locale" page version (example.com/en/).
Start your tests from a landing page and then navigate to the specific "locale" version:
await t
.click(Selector('#choose-lang-combo')
.click(Selector('#en-lang'))
Try to add your own Accept-Language header to your request.
Use a custom user profile. Maybe just using the --lang flag (testcafe chrome --lang=es) will help you (without the custom user profile):
For example, to create a shortcut that launches Google Chrome in Spanish (es), you might create a shortcut named chrome-es that has the following target:path_to_chrome.exe --lang=es --user-data-dir=c:\chrome-profile-es
Related
I have an automatic test suite that uses Selenium to control a Chrome browser with a particular version. However Chrome tries to update itself between test runs. How do I prevent Chrome from automatically updating itself?
Removing write permission from the Google Chrome binary appears to prevent it from self-updating, at least on macOS.
In Python you can do that with code that looks like:
import subprocess
def remove_write_permissions(itempath: str) -> None:
subprocess.run([
'chmod',
'-R',
'a-w',
itempath
], check=True, capture_output=True)
remove_write_permissions('/Applications/Google Chrome.app')
I've only tested this code on macOS. It probably also works on Linux, but probably not Windows.
I have looked around online and quite a bit on stackoverflow and cant seem to find an up-to-date answer for this question. I have found other questions here, here, and here - and none of those solution work anymore. Does anyone know if this functionality is available in Cypress or if there's a way to force a locale change? Thanks
That's not too easy - as this differs from the browser you will be running your tests in.
Also, I believe that only are testing that your application looks and behaves right when the USER selected a specific language, you should consider adding a parameter when initiating your test session, e.g.
http://myapp.com/start?lang=en
then storing the selected language in LocaleStorage or a Cookie and selecting the language from there, as it is a lot more portable - and you will have users wanting to use your application in a different language than the browser default.
Still, There might be a few scenarios (e.g. if you want to tests, that your application detects the browser language correctly) where setting the browser language can be required, but I would suggest keeping tests that rely on a browser configuration to a minimum.
Is is possible tho, at least for Electron (verified with Electron 100) and Firefox (verified with Firefox 102). It used to work in Chrome too, but doesn't work for me anymore.
For Electron:
As Electron is being started along with the cypress GUI, changing the language afterwards is not possible. But you can expose an environment variable to the process, e.g.
ELECTRON_EXTRA_LAUNCH_ARGS=--lang=en npx cypress open
to start electron with the wanted locale.
For Firefox:
In your cypress.config.ts expand the defineConfig to contain such a block:
export default defineConfig({
// ...
e2e: {
// ....
setupNodeEvents(on, config) {
on('before:browser:launch', (browser, launchOptions) => {
if (browser.family === 'firefox') {
launchOptions.preferences['intl.locale.requested'] = "en_US"
return launchOptions
}
}
}
}
The Firefox Setup will only work, if you have no other Firefox instance running in another locale.
I was looking at https://github.com/DevExpress/testcafe-browser-provider-electron repository.
To automate electron apps using testcafe, I see we need to provide "mainWindowUrl" in .testcafe-electron-rc . Regular electron apps have index.html files in it which I can pass to mainWindowUrl but I'm not sure what should we pass for executable electron apps like atom.exe/vscode.exe.
TestCafe will show a list of URLs opened during the app initialization time if it fails to find the main window URL. You can specify an empty string as a value of mainWindowUrl, wait until TestCafe shows an error and use links from the displayed list.
To test executable electron applications you should configure the 'testcafe-browser-provider-plugin' in another way. See the Testing an Executable Electron Application section for more information.
I am trying to use testcafe-browser-provider-saucelabs.
My tests can successfully connect to SauceLabs and run there, but testcafe creates a unique sauceconnect tunnel, whereas I need to use a shared tunnel. Also, screenResolution is not being picked up from sauceLabsConfig.json file.
I have saucelabs credentials set as environment variables.
I am launching tests using these commands:
export SAUCE_JOB="Regression Job"
export SAUCE_BUILD="Build 1"
export SAUCE_CONFIG_PATH="./sauceLabsConfig.json"
testcafe saucelabs:chrome tests/
I created a sauce config JSON file:
{
"parentTunnel": "PARENT_TUNNEL",
"tunnelIdentifier": "qa",
"screenResolution": "1920x1080"
}
Why is my SAUCE_CONFIG_PATH variable not working?
At present, not all SauceLabs options are supported for the 'testcafe-browser-provider-saucelabs'. For example, the tunnelIdentifier option is not supported. I've created an issue in the browser provider repository. Track it be informed about the progress.
Note that this issue seems to be fixed, per this pull request:
https://github.com/DevExpress/saucelabs-connector/pull/33
...and integrated in to testcafe 1.14.0:
https://github.com/DevExpress/testcafe/tree/v1.14.0
The Durandal Test Framework runs Jasmine tests within PhantomJS.
Where I'm implementing this for the first time I'm getting a lot of errors, and reading through these on the command prompt is proving to be very tedious.
If I load up the spec.html file in my web browser, it tells me that no specs were found:
Yet PhantomJS is able to find the specs with no problem:
Is there a way I can configure these Jasmine tests to run through my web browser and not through (or as well as) PhantomJS?
I've set up a new index.html file and have replaced the var runTests = ... section with a simple require() call:
require(['../test/specs/system.spec.js']);
Durandal's system.spec.js file is loaded in the browser, but Jasmine is still stating that no specs were found.
Jasmine's tests weren't being run because I wasn't telling it to re-execute. The solution to this was to simply re-execute by calling this within the require callback:
require(['../test/specs/system.spec.js'], function() {
jasmine.getEnv().execute();
});
Note: A drawback of this is that the 'no specs found' bar is still present and the 'raise exceptions' control on the re-executed specs doesn't appear to function: