How to create data driven test using Nightwatch.js?
I am using data.js file as global. The content is:
module.exports={
username:'xyz#gmail.com',
password:'12345',
urls: {
login: 'http://www.asdf.com'
}
};
By giving the your file path value in key "globals_path" of your nightwatch.json file like below, you don't need to rename your js file , you can use data.js file as global file:
"globals_path" : "path/to/data.js",
and in your test file you can call variable like this :
browser.globals.username etc
Related
I need to load a different .env file, named .env.staging under certain conditions.
In .env file
APP_NAME="Laravel"
APP_ENV=staging
APP_KEY=
APP_DEBUG=true
APP_URL=
But my .env.staging file is not loaded. How to load different .env
Test my way: Create env folder in root folder with 2 environement files.
Content of env\.env.staging:
APP_NAME="STAGING MODE"
APP_KEY=base64:AjYSIS9myYGnVkdfaXy2Oz6lY/ofyNhuqN9ZtkKaNm0=
APP_DEBUG=true
APP_URL=http://localhost
Content of env\.env.test
APP_NAME="TEST MODE"
APP_KEY=base64:AjYSIS9myYGnVkdfaXy2Oz6lY/ofyNhuqN9ZtkKaNm0=
APP_DEBUG=true
APP_URL=http://localhost
Then set this code to boot file bootstrap\app.php:
<?php
use Dotenv\Dotenv;
$app = new Illuminate\Foundation\Application(
$_ENV['APP_BASE_PATH'] ?? dirname(__DIR__)
);
// Load temporary environement variables
$dotenv = Dotenv::createImmutable(__DIR__, '../.env');
$dotenv->load();
// Get dynamic APP_ENV wrote in .env file
$env = $_ENV['APP_ENV'];
// You can debug by command var_dump to check
// var_dump($env);
switch ($env) {
case 'staging':
// Overwrite existing environement variables
$dotenv = Dotenv::createMutable(__DIR__ .'/../env', '.env.staging');
$dotenv->load();
break;
case 'test':
// Overwrite existing environement variables
$dotenv = Dotenv::createMutable(__DIR__ .'/../env', '.env.test');
$dotenv->load();
break;
default:
break;
}
Create a route with a view has this title:
<title>{{ env('APP_NAME') }}</title>
When you change variable APP_ENV in .env file:
APP_ENV=test
You will get the title “TEST MODE”
If you change to:
APP_ENV=staging
You will get the title “STAGING MODE”
The title changed, mean the environement variables are loaded!
Tested with "laravel/framework": "^8.75" version has built-in package "vlucas/phpdotenv": "^5.4.1".
To use the .env.test file try to restructure your initial bootstrap() method inside of the App/Http/Kernel.php file to look like this:
public function bootstrap()
{
app()->loadEnvironmentFrom('.env.staging');
parent::bootstrap();
}
I have defined wdio.conf.js file (main file) and environment specific dev-chrome.conf.js file.
I can't get get cucumber to recognize my step definitions folder.
This is my structure:
And this is what I have in dev-chrome.config.js file:
const wdioConfig = require('../../../../../wdio.conf.js');
const commands = require('../../../../../src/commands/commands');
wdioConfig.config.cucumberOpts = [{
// other stuff here
require:
[
'./src/step_definitions/**/*.js',
// Or search a (sub)folder for JS files with a wildcard
// works since version 1.1 of the wdio-cucumber-framework
//'./src/**/*.js',
],
// other stuff here
}];
exports.config = wdioConfig.config;
I am getting an error:
"Step "When I add the product to a cart" is not defined. You can ignore this error by setting cucumberOpts.ignoreUndefinedDefinitions as true."
When I have same path for step definitions defined on main wdio.conf.js file then it works.
My main wdio.conf.js file is located in the root folder of the project.
Do you know how could I make it work in the environment specific conf.js file?
I am using #wdio/cucumber-framework": "^5.13.2"
As per the below example config, the cucumberopts should be an object and I think you are trying to set it as an array.
https://github.com/amiya-pattnaik/webdriverIO-with-cucumberBDD/blob/master/test/config/suite.cucumber.conf.js#L156
Maybe you should follow this example which will help to understand config setup.
Cheers!
I have a problem, I have already generated OpenApi Swagger files (swagger.json and swagger.yaml) Is it possible somehow in Ktor (kotlin) import this files and start swagger-ui server on specific route ?
I have visited ktor-swagger project but could get how just to add json file to display swagger-ui.
Any suggestions ?
Make you json file accessible from static routing
Create "files" directory in resources dir
Use next code to routing static files from "files" dir
routing {
static("/static") {
resources("files")
}
//...
}
Lets name json file "test.json", then put you it in "files" folder
so now you run the app and see this file by http://localhost:8080/static/test.json
Then we need to install and configure OpenApiGen
Add OpenApiGen dependencies you can find how to do this here https://github.com/papsign/Ktor-OpenAPI-Generator
Then use the following code
install(OpenAPIGen) {
serveSwaggerUi = true
swaggerUiPath = "/swagger-ui"
}
now you can use http://localhost:8080/swagger-ui/index.html?url=/static/test.json URL to see your file through the swagger UI
Also, you can provide your own route to using redirection
get("/api") {
call.respondRedirect("/swagger-ui/index.html?url=/static/test.json", true)
}
this will allow you to use just http://localhost:8080/api
Having made a .xsaccess file and a .xsapp file, I can access my UI5 application on https://host:8000/app/index.html. It does however give me 404's on non-HTML files in the same folder and subfolders, for instance my manifest, Component and other JS files. XSJS files seem OK.
Am I missing a setting somewhere?
Try adding the following code in your .xsaccess and see if it works.
{
"exposed" : true,
"authentication" : [{"method":"Basic"}],
"cache_control" : "no-cache, no-store",
"cors" : {
"enabled" : false
}
}
Our backbone app uses gon. When we try to run our tests, we are getting a gon is undefined error in the console of the browser. Our layout file includes a call to include_gon, but that file is not being loaded by jasmine, so jasmine is failing in our first javascript file that contains gon. We tried creating a helper to assign the gon variable to an empty hash (like a fixture), but the helper was called after the first call to gon and therefore didn't fix our issue.
The secret was to use the asset pipeline to define the load order of my files. I commented out these lines from jasmine.yml
# path to parent directory of src_files
# relative path from Rails.root
# defaults to app/assets/javascripts
#src_dir: "app/assets/javascripts"
# list of file expressions to include as source files
# relative path from src_dir
#src_files:
# - "application.{js.coffee,js,coffee}"
And created spec.js.coffee with these lines:
#= require application
#= require jasmine-jquery
Now my js files get loaded in order and I am good to go.
What worked for me was to define window.gon = {} inside the test like so:
describe("A suite is just a function", function() {
beforeEach(function() {
window.gon = {}
gon.test = "this"
})
it ("should find gon", function() {
expect(gon.test).toBe("this")
})
})