Current base url in _bootstrap file (Codeception) - codeception

Is there a way to have current base URL in _bootstrap file for my acceptance test ?
Or
Is there a way to have current environment in _bootstrap file for my acceptance test ?
Actually, I use environment variable to test different sites :
env:
env1:
modules:
config:
WebDriver:
url: 'http://local.env1.fr/'
env2:
modules:
config:
WebDriver:
url: 'http://local.env2.fr/'

Finaly I find a variable with current environment.
$settings["current_environment"]

The WebDriver has a method with the name
public function _getUrl()
$url = $I->_getUrl();
https://github.com/Codeception/Codeception/blob/2.0/src/Codeception/Module/WebDriver.php#L207
It seems, that it doesn't work, because the builded WebGuy class hasn't such a method. I guess the _bootstrap.php file hasn't the possibility to read the config. Only a special "module" could read it's own config by passing the config array as argument by the constructor.

Related

Set env variables in Cypress using Vite

I'm using VueJs 3 with Vite and Cypress.
In my app I have an environment variable to define my URL:
const url = import.meta.env.VITE_URL
My goal is to replace this VITE_URL in Cypress. I've tried to create a cypress.env.json file in which I wrote:
{
"VITE_URL": "https://...",
}
but it's not working. I've also tried with CYPRESS_URL or CYPRESS_VITE_URL, but I get the same result. Any idea?
Ok, I solved it. I created a .env.testing file that I use by specifying --mode testing in the npm command that launches cypress.
This env.testing has the properties defined like:
'VITE_URL="http://..."'
If you've declared the value in a cypress.env.json file, you can reference it in code with `Cypress.env('varName');
Cypress.env('VITE_URL');

Why is runtimeConfig doesn't see environment variables in Nuxt 3?

I do yarn build without the .env file
Add the .env file to the project
I do yarn start.
Print the useRuntimeConfig().public.baseURL to the console and get undefined.
Why is runtime not tracking my environment variables?
.env
NUXT_PUBLIC_BASE_URL=https://example.com/api/v1
nuxt.config.js
export default defineNuxtConfig({
runtimeConfig: {
public: {
baseUrl: ''
}
},
plugins/app.js
export default defineNuxtPlugin(() => {
console.log('baseURL', useRuntimeConfig().public.baseURL
})
From the documentation page:
However, after your server is built, you are responsible for setting environment variables when you run the server. Your .env file will not be read at this point. How you do this is different for every environment. On a Linux server, you could pass the environment variables as arguments using the terminal DATABASE_HOST=mydatabaseconnectionstring node .output/server/index.mjs. Or you could source your env file using source .env && node .output/server/index.mjs.
Note that for a purely static site, it is not possible to set runtime configuration config after your project is prerendered.
So, source .env && yarn start should do it.
You might check the version of nuxt.
If it's the bridge version, runtimeConfig cannot work.
Cause I use #nuxt/bridge, not work.
and then it worked on the 3.0.0-rc.3 version. I've tried.
baseUrl: process.env.NUXT_PUBLIC_BASE_URL
try it that way. what you do is setting it explicitly to a empty string.

Can I use a %variable% in module section of codeception environment file?

I tried to have the server address injected to the test with environment variable ABSOLUTE_URL so PhpBrowser would test against it. The config I wanted to do is something like this:
class_name: AcceptanceTester
modules:
enabled:
- PhpBrowser:
url: "%ABSOLUTE_URL%"
But I simply could not get it to work. Is there anyway I can do it?
Add params section to codeception.yaml file:
params:
- env
Documented at https://codeception.com/docs/06-ModulesAndHelpers#Dynamic-Configuration-With-Parameters

swiper with rollupjs is asking for dom7_modular

When I try to use swiper with rollup I get this:
(!) Missing global variable name
Use output.globals to specify browser global variable names
corresponding to external modules
dom7/dist/dom7.modular (guessing 'dom7_modular')
created public/build/bundle.js in 1.6s
and in the console
main.js:8 Uncaught ReferenceError: dom7_modular is not defined
at main.js:8
any idea about this?
resolve({
browser: true,
dedupe: ['svelte'],
extensions: ['.svelte','.js']
}),
I added just .js to extensions in the rollup config and it was done

Run Same Testcafe tests with different URLs per environment

I am working on a TestCafe proof of concept. I have a few tests working in one test environment. I need a way to run the same tests in up to 3 different test environments that have different URLs. Is there a best practice for this scenario?
A solution is to add custom options on the testcafe command-line like for example : --env=uat.
Use minimist to read all custom options that you have added to the TestCafe command-line and export a config object like this:
import * as minimist from 'minimist';
const args = minimist(process.argv.slice(2));
// get the options --env=xxx --user=yyy from the command line
export const config = {
env: args.env,
user: args.user,
};
Then import that config object wherever you need it in the test code.
see How do I work with configuration files and environment variables? for more details.
In v1.20.0 and later, TestCafe offers a way to specify the baseUrl in the test run setup:
CLI
Program API runner.run({baseUrl})
Config file
You can use this approach along with environment variables or custom command line arguments to determine what url should be assigned to the baseUrl option.
Alternatively, you can have a different configuration file for each test run setup and switch between these files using the --config-file option.