Karate - how to put variable value into driver configuration (configure in JS, read values in features - background) - automated-tests

I am not able to use variable in driver configuration (feature file Background).
1)variable is defined in JS configuration file (karate-config.js):
config.driverType = 'geckodriver';
config.driverExecutable = 'geckodriver';
config.driverStart = false;
config.driverPort = 4444;
2)in feature file (Background section) I need to modify driver according to the variable values:
configure driver = { type: driverType, executable: driverExecutable, start: driverStart, port: driverPort}
to have same result to this (this works):
configure driver = { type: 'geckodriver', executable: 'geckodriver', start: false, port: 4444}
3) when I wrote the variable "print driverType" in scenario, value is printed correctly:
[print] geckodriver
but driver configuration fails:
WARN com.intuit.karate - unknown driver type: driverType, defaulting to 'chrome'
ERROR com.intuit.karate - driver config / start failed: class java.lang.String cannot be cast to class java.lang.Boolean (java.lang.String and java.lang.Boolean are in module java.base of loader 'bootstrap'), options: {type=chrome, executable=driverExecutable, start=driverStart, port=driverPort, target=null}
Could you help me with solving this to be able to change driver settings in JS file (generally - how to insert variable into driver configuration)?
Thank you.

Just make this change:
* configure driver = { type: '#(driverType)', executable: '#(driverExecutable)', start: '#(driverStart)', port: '#(driverPort)' }
Or this should also work:
* configure driver = ({ type: driverType, executable: driverExecutable, start: driverStart, port: driverPort })
There is a subtle difference, explained here: https://github.com/intuit/karate#enclosed-javascript
By the way, you can do the config like this also in karate-config.js:
config.driverConfig = { type: 'geckodriver', executable: 'geckodriver' };
And this would work in the feature file:
* configure driver = driverConfig
And you can do the driverConfig completely in the karate-config.js if you want:
* karate.configure('driver', { type: 'geckodriver', executable: 'geckodriver' });

Related

Karate : headless chromedriver not working ,giving error as "chrome server returned empty list"

detailed Error i am getting is as below :
` [2.1:58] test.feature:58 - evaluation of 'karate-config.js' failed: javascript function call failed: com.intuit.karate.exception.KarateException:
Create.feature:21 - driver config / start failed: chrome server returned empty list from http://localhost:59435, options: {type=chrome, headless=true, showDriverLog=true, addOptions=["--no-sandbox","--windows-size=1080,1920","--disable-web-security","--credentials_enable_service=false","--profile.password_manager_enabled=false"], pollInterval=1000, pollAttempts=60, port=59435, target=null}
src.smoke.java.com..test: [1.1:30] test.feature:30 - evaluation of 'karate-config.js' failed: javascript function call failed: com.intuit.karate.exception.KarateException:
`
Below is chrome driver options setup, interestingly scripts get executed successfully when headless:false
function configureChromeForUITests(){
var chromePort = parseInt( Math.floor(50000 + Math.random() * Math.floor(15534)),10);
var IntegerType = Java.type('java.lang.Integer');
var chromePortIntObj = new IntegerType(chromePort);
var chromeDriverObject = {
type: 'chrome',
//executable: '/opt/homebrew/bin/chromedriver',
headless:true,
showDriverLog: true,
addOptions: [
'--no-sandbox',
'--windows-size=1080,1920',
'--disable-web-security',
'--credentials_enable_service=false',
'--profile.password_manager_enabled=false'
],
// webDriverSession: chromeSession,
pollInterval:1000,
pollAttempts: 60,
port: chromePortIntObj,
};
Tried giving executable path as executable: '/opt/homebrew/bin/chromedriver'

Not able to execute lifecycle operation using script plugin

I'm trying to learn how to use script plugin. I'm following script plugin docs here but not able to make it work.
I've tried to use the plugin in two ways. The first, when cloudify.interface.lifecycle.start operation is mapped directly to a script:
tosca_definitions_version: cloudify_dsl_1_3
imports:
- 'http://www.getcloudify.org/spec/cloudify/4.5.5/types.yaml'
node_templates:
Import_Project:
type: cloudify.nodes.WebServer
capabilities:
scalable:
properties:
default_instances: 1
interfaces:
cloudify.interfaces.lifecycle:
start:
implementation: scripts/create_project.sh
inputs: {}
The second with a direct mapping:
tosca_definitions_version: cloudify_dsl_1_3
imports:
- 'http://www.getcloudify.org/spec/cloudify/4.5.5/types.yaml'
node_templates:
Import_Project:
type: cloudify.nodes.WebServer
capabilities:
scalable:
properties:
default_instances: 1
interfaces:
cloudify.interfaces.lifecycle:
start:
implementation: script.script_runner.tasks.run
inputs:
script_path: scripts/create_project.sh
I've created a directory named scripts and placed the below create_project.sh script in this directory:
#! /bin/bash -e
ctx logger info "Hello to this world"
hostname
I'm getting errors while validating the blueprint.
Error when operation is mapped directly to a script:
[2019-04-13 13:29:40.594] [DEBUG] DslParserExecClient - got output from dsl parser Could not extract plugin from operation mapping 'scripts/create_project.sh', which is declared for operation 'start'. In interface 'cloudify.interfaces.lifecycle' in node 'Import_Project' of type 'cloudify.nodes.WebServer'
in: /opt/cloudify-composer/backend/dev/workspace/2/tmp-27O0e1t813N6as
in line: 3, column: 2
path: node_templates.Import_Project
value: {'interfaces': {'cloudify.interfaces.lifecycle': {'start': {'implementation': 'scripts/create_project.sh', 'inputs': {}}}}, 'type': 'cloudify.nodes.WebServer', 'capabilities': {'scalable': {'properties': {'default_instances': 1}}}}
Error when using a direct mapping:
[2019-04-13 13:25:21.015] [DEBUG] DslParserExecClient - got output from dsl parser node 'Import_Project' has no relationship which makes it contained within a host and it has a plugin 'script' with 'host_agent' as an executor. These types of plugins must be installed on a host
in: /opt/cloudify-composer/backend/dev/workspace/2/tmp-279QCz2CV3Y81L
in line: 2, column: 0
path: node_templates
value: {'Import_Project': {'interfaces': {'cloudify.interfaces.lifecycle': {'start': {'implementation': 'script.script_runner.tasks.run', 'inputs': {'script_path': 'scripts/create_project.sh'}}}}, 'type': 'cloudify.nodes.WebServer', 'capabilities': {'scalable': {'properties': {'default_instances': 1}}}}}
What is missing to make this work?
I also found the Cloudify Script Plugin examples from their documentation do not work: https://docs.cloudify.co/4.6/working_with/official_plugins/configuration/script/
However, I found I can make the examples work by adding an executor line in parallel with the implementation line to override the host_agent executor as follows:
tosca_definitions_version: cloudify_dsl_1_3
imports:
- 'http://www.getcloudify.org/spec/cloudify/4.5.5/types.yaml'
node_templates:
Import_Project:
type: cloudify.nodes.WebServer
capabilities:
scalable:
properties:
default_instances: 1
interfaces:
cloudify.interfaces.lifecycle:
start:
implementation: scripts/create_project.sh
executor: central_deployment_agent
inputs: {}

Homestead not loading the page (symfony)

I am working on Mac OSX El Capitan 10.11.2. I am quite new to vagrant and this would be my first project in Symfony. I set up the environment to start my first symfony 4 project. Everything was installed correctly (including VirtualBox, Vagrant). I updated my hosts file, I edited Homestead.yaml and at the end when I wanted to access my domain (symf01.test) in Chrome I get a message that this site can't be reached and a text file is downloaded automatically, containing such information:
<?php
use Symfony\Component\Debug\Debug;
use Symfony\Component\HttpFoundation\Request;
require dirname(__DIR__).'/config/bootstrap.php';
if ($_SERVER['APP_DEBUG']) { unmask(0000);
Debug::enable();}
if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? $_ENV['TRUSTED_PROXIES'] ?? false)
{ Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);}
if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? $_ENV['TRUSTED_HOSTS'] ?? false)
{ Request::setTrustedHosts([$trustedHosts]);}
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
$request = = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
This is my Homestead.yaml file:
ip:"192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: /Users/username/Homestead/code/simba
to: /home/vagrant/simba
type: "nfs"
sites:
- map: symf01.test
to: /home/vagrant/simba/public
type: symfony
databases:
- homestead
# ports:
# - send: 50000
# to: 5000
# - send: 7777
# to: 777
# protocol: udp
# blackfire:
# - id: foo
# token: bar
# client-id: foo
# client-token: bar
# zray:
# If you've already freely registered Z-Ray, you can place the token here.
# - email: foo#bar.com
# token: foo
# Don't forget to ensure that you have 'zray: "true"' for your site.
This is what I get when I run serve nginx status
For future reference, this helped:
...
sites:
- map: symf01.test
to: /home/vagrant/simba/public
type: symfony
to
...
sites:
- map: symf01.test
to: /home/vagrant/simba/public
type: "symfony4"
Difference is in syntax. Value of type needs to be under quotes.
That type tells Homestead how to modify .htaccess files so that your websites can be properly accessed.

Health endpoint not working in spring-boot-actuator service

Hi I am using spring boot version - 2.0.0.RC1. I have simple service running #port 9400.
My application.properties have below configuration:
spring.main.banner-mode = CONSOLE
spring.profiles.active = ${profile:local}
server.compression.enabled = true
server.compression.min-response-size = 1
server.compression.mime-types = application/json,application/xml,text/xml,text/plain
banner.charset = UTF-8
management.endpoints.health.show-details=true
management.server.address: 127.0.0.1
management.endpoints.web.expose: health,info,metrics,mappings,trace
management.endpoints.health.show-details: true
management.endpoints.health.time-to-live: 2000
management.security.enabled: false
management.health.defaults.enabled: false
management.health.diskspace.enabled: true
My build.gradle has :
dependencies {
// Spring Boot
compile group: 'org.springframework.boot', name: 'spring-boot-starter-webflux', version: springBootVersion
compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator', version: springBootVersion
}
My gradle.properties:
springBootVersion = 2.0.0.RC1
When I point to http://127.0.0.1:9400/health
I get error screen as attached snapshot.
What am I missing?
The show-details value that you are providing is not a valid one...
Anyway, in Spring Boot 2.0 the actuator endpoints (like the health) are remapped to /actuator/*.
Now, the health is located at /actuator/health.
More info at the release notes in https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.0.0-RC2-Release-Notes#health-endpoint
Just add the following property in application.properties file:
management.health.defaults.enabled=false

How can I found that the Rscript have been run successfully on the docker by the CWL?

I have written the CWL code which runs the Rscript command in the docker container. I have two files of cwl and yaml and run them by the command:
cwltool --debug a_code.cwl a_input.yaml
I get the output which said that the process status is success but there is no output file and in the result "output": null is reported. I want to know if there is a method to find that the Rscript file has run on the docker successfully. I want actually know about the reason that the output files are null.
The final part of the result is:
[job a_code.cwl] {
"output": null,
"errorFile": null
}
[job a_code.cwl] Removing input staging directory /tmp/tmpUbyb7k
[job a_code.cwl] Removing input staging directory /tmp/tmpUbyb7k
[job a_code.cwl] Removing temporary directory /tmp/tmpkUIOnw
[job a_code.cwl] Removing temporary directory /tmp/tmpkUIOnw
Removing intermediate output directory /tmp/tmpCG9Xs1
Removing intermediate output directory /tmp/tmpCG9Xs1
{
"output": null,
"errorFile": null
}
Final process status is success
Final process status is success
R code:
library(cummeRbund)
cuff<-readCufflinks( dbFile = "cuffData.db", gtfFile = NULL, runInfoFile = "run.info", repTableFile = "read_groups.info", geneFPKM = "genes.fpkm_trac .... )
#setwd("/scripts")
sink("cuff.txt")
print(cuff)
sink()
My cwl file code is:
class: CommandLineTool
cwlVersion: v1.0
id: cummerbund
baseCommand:
- Rscript
inputs:
- id: Rfile
type: File?
inputBinding:
position: 0
- id: cuffdiffout
type: 'File[]?'
inputBinding:
position: 1
- id: errorout
type: File?
inputBinding:
position: 99
prefix: 2>
valueFrom: |
error.txt
outputs:
- id: output
type: File?
outputBinding:
glob: cuff.txt
- id: errorFile
type: File?
outputBinding:
glob: error.txt
label: cummerbund
requirements:
- class: DockerRequirement
dockerPull: cummerbund_0
my input file (yaml file) is:
inputs:
Rfile:
basename: run_cummeR.R
class: File
nameext: .R
nameroot: run_cummeR
path: run_cummeR.R
cuffdiffout:
- class: File
path: cuffData.db
- class: File
path: genes.fpkm_tracking
- class: File
path: read_groups.info
- class: File
path: genes.count_tracking
- class: File
path: genes.read_group_tracking
- class: File
path: isoforms.fpkm_tracking
- class: File
path: isoforms.read_group_tracking
- class: File
path: isoforms.count_tracking
- class: File
path: isoform_exp.diff
- class: File
path: gene_exp.diff
errorout:
- class: File
path: error.txt
Also, this is my Dockerfile for creating image:
FROM r-base
COPY . /scripts
RUN apt-get update
RUN apt-get install -y \
libcurl4-openssl-dev\
libssl-dev\
libmariadb-client-lgpl-dev\
libmariadbclient-dev\
libxml2-dev\
r-cran-plyr\
r-cran-reshape2
WORKDIR /scripts
RUN Rscript /scripts/build.R
ENTRYPOINT /bin/bash
I got the answer!
There were some problems in my program.
1. The docker was not pulled correctly then the cwl couldn't produce any output.
2. The inputs and outputs were not defined mandatory. So I got the success status in the case which I did not have proper inputs and output.

Resources