Nightwatch globals variable can't get on jenkins - jenkins

Why the Nightwatch globals variable can't get on Jenkins?
I added below in the nightwatch.js
"globals_path": "global.js"
And the test like this
module.exports = {
"#tags": ["jenkins"],
"Test on jenkins": browser => {
let TEST_ONE = browser.globals.TEST_ONE;
console.log(TEST_ONE);
console.log(browser.globals);
}
}
This is my globlas.js
module.exports = {
TEST_ONE: "Hellow world"
};
When I run it in local it works well
But it can't get the globals variable on Jenkins
The console on the Jenkins
{
abortOnAssertionFailure: true,
waitForConditionPollInterval: 500,
waitForConditionTimeout: 5000,
throwOnMultipleElementsReturned: false,
suppressWarningsOnMultipleElementsReturned: false,
asyncHookTimeout: 10000,
unitTestsTimeout: 2000,
customReporterCallbackTimeout: 20000,
retryAssertionTimeout: 5000,
reporter: [Function: reporter]
}
The console on my local
{
abortOnAssertionFailure: true,
waitForConditionPollInterval: 500,
waitForConditionTimeout: 5000,
throwOnMultipleElementsReturned: false,
suppressWarningsOnMultipleElementsReturned: false,
asyncHookTimeout: 10000,
unitTestsTimeout: 2000,
customReporterCallbackTimeout: 20000,
retryAssertionTimeout: 1000,
reporter: [Function],
TEST_ONE: 'Hellow world',
}```

I got the answer
Just add this in the Jenkins shell
#!/bin/sh -l

Related

cypress 12 docker throw error socket_posix.cc(93)] CreatePlatformSocket() failed: Address family not supported by protocol (97)

I upgraded my cypress version from cypress 8 to cypress 12.
I am executing all my test cases on jenkins server OS centos 7 using base image cypress/base:16.13.0.
When I executed all the test cases on my local window 10 using same docker image cypress/base:16.13.0 and "cypress": "^12.3.0",All works perfectly good.
BUT when I trying to run the same project on Jenkins server centos 7 OS, throw an error
[476:0123/104731.525262:ERROR:socket_posix.cc(93)] CreatePlatformSocket() failed: Address family not supported by protocol (97)
Note : When I executed the same package (test cases) on cypress 8 all works good.
Kindly suggest me how to fix this?
cypress.config.js file :
const { defineConfig } = require('cypress');
const createBundler = require('#bahmutov/cypress-esbuild-preprocessor');
const addCucumberPreprocessorPlugin =
require('#badeball/cypress-cucumber-preprocessor').addCucumberPreprocessorPlugin;
const createEsbuildPlugin =
require('#badeball/cypress-cucumber-preprocessor/esbuild').createEsbuildPlugin;
module.exports = defineConfig({
defaultCommandTimeout: 5000,
numTestsKeptInMemory: 0,
viewportWidth: 1360,
viewportHeight: 768,
env: {
username: 'xxxx',
password: '',
},
"retries": 1,
"video": false,
e2e: {
// Integrate #bahmutov/cypress-esbuild-preprocessor plugin.
async setupNodeEvents(on, config) {
const bundler = createBundler({
plugins: [createEsbuildPlugin(config)],
});
// This is required for the preprocessor to be able to generate JSON reports after each run, and more,
on('file:preprocessor', bundler);
await addCucumberPreprocessorPlugin(on, config);
return config;
},
specPattern: 'cypress/e2e/**/*.feature',
},
});
Package.json
"#badeball/cypress-cucumber-preprocessor": "^15.1.0",
"#deepakvishwakarma/cucumber-json-formatter": "^0.0.3",
"cypress": "^12.3.0",
"moment": "^2.29.4",
"multiple-cucumber-html-reporter": "^3.1.0"
},
"dependencies": {
"#bahmutov/cypress-esbuild-preprocessor": "^2.1.5",
"cypress-xpath": "^2.0.1"
},
"cypress-cucumber-preprocessor": {
"stepDefinitions": "cypress/e2e/**/*.cy.js",
"commonPath": "cypress/e2e/common/**/*.cy.js",
"filterSpecs": true,
"omitFiltered": true,
"nonGlobalStepDefinitions": true,
"json": {
"enabled": true,
"output": "cypress/cucumber_report/log.json",
"formatter": "node",
"args": [
"./node_modules/#deepakvishwakarma/cucumber-json-formatter/lib/main.js"
]
},
"cucumberJson": {
"generate": true,
"outputFolder": "cypress/cucumber_report",
"filePrefix": "",
"fileSuffix": ".cucumber"
}
}
}

Appium - Codeceptjs - Gherkin, can not execute steps script and config failed

I've got some issues with codeceptjs appium.
I run test script by npx codeceptjs run , it did not execute the step_definitions file.
I config steps definition with /*steps.js and its not working, i have to direct exact path of steps file.
The app crashed without throw exception, the script still being execute.
add-task.feature
Feature: Add task
Background: I opened the application
Scenario: Add task
Given I click Add Task button
And I input all information
add-task-steps.js
When("I input all information", () => {
AddTaskScreen.inputTaskName('sdsada')
});
const HomeScreen = require("../screens/home-screen.js")
const { I } = inject();
home-screen-steps.js
Given("I click Add Task button", () => {
HomeScreen.tapAddTaskButton();
});
Details
CodeceptJS version: ^3.3.6
NodeJS Version: 8.15.0
Operating System: Windows 10
webdriverio 7.25.2
Configuration file:
exports.config = {
output: './output',
helpers: {
Appium: {
app: 'Appium/ToDoList.apk',
platform: 'Android',
device: 'emulator-5556'
}
},
include: {
I: './steps_file.js',
env:{
TIMEOUT: 5000,
}
},
mocha: {},
bootstrap: null,
timeout: null,
teardown: null,
hooks: [],
gherkin: {
features: './features/*.feature',
steps: ['./step_definitions/home-screen-steps.js']
},
plugins: {
screenshotOnFail: {
enabled: true
},
tryTo: {
enabled: true
},
retryFailedStep: {
enabled: false
},
retryTo: {
enabled: true
},
eachElement: {
enabled: true
},
pauseOnFail: {}
},
stepTimeout: 10000,
stepTimeoutOverride: [{
pattern: 'wait.*',
timeout: 0
},
{
pattern: 'amOnPage',
timeout: 0
}
],
tests: './*_test.js',
name: 'appium'
}
Thanks in advance. <3
I resolved it by replace waitForElementToBeClickable with waitForElement.
Idk why Codeceptjs not recognize waitForElementToBeClickabe and also not throw any exception.

Vue CLI HMR not working after upgrading to v5

I'm developing a Django+Vue app using VSCode devcontainers (Docker).
I have recently migrated from Vue CLI v4 to Vue CLI v5 following the migration guide.
After the migration, the HMR of the dev-server stopped working.
This was my vue.config.js before the migration:
const BundleTracker = require("webpack-bundle-tracker");
module.exports = {
publicPath: process.env.NODE_ENV === "development" ? "http://localhost:8080/" : "/static/",
devServer: {
host: "0.0.0.0",
port: 8080,
public: "0.0.0.0:8080",
https: false,
headers: { "Access-Control-Allow-Origin": ["*"] },
hotOnly: true,
watchOptions: {
ignored: "./node_modules/",
aggregateTimeout: 300,
poll: 1000,
},
},
transpileDependencies: ["vuetify"],
css: {
sourceMap: true,
},
chainWebpack: (config) => {
config.plugin("BundleTracker").use(BundleTracker, [
{
filename: `./config/webpack-stats-${process.env.NODE_ENV}.json`,
},
]);
config.resolve.alias.set("__STATIC__", "static");
},
};
And after:
const { defineConfig } = require("#vue/cli-service");
const BundleTracker = require("webpack-bundle-tracker");
module.exports = defineConfig({
publicPath: process.env.NODE_ENV === "development" ? "http://localhost:8080/" : "/static/",
devServer: {
host: "0.0.0.0",
port: 8080,
client: {
webSocketURL: "auto://0.0.0.0:8080/ws",
},
https: false,
headers: { "Access-Control-Allow-Origin": ["*"] },
hot: "only",
static: {
watch: {
ignored: "./node_modules/",
aggregateTimeout: 300,
poll: 1000,
},
},
},
transpileDependencies: ["vuetify"],
css: {
sourceMap: true,
},
chainWebpack: (config) => {
config.plugin("BundleTracker").use(BundleTracker, [
{
filename: `./config/webpack-stats-${process.env.NODE_ENV}.json`,
},
]);
config.resolve.alias.set("__STATIC__", "static");
},
});
After the migration, a new warning shows everytime I run npm run serve (but devServer.public has been removed in v5!):
App running at:
- Local: http://localhost:8080/
It seems you are running Vue CLI inside a container.
Since you are using a non-root publicPath, the hot-reload socket
will not be able to infer the correct URL to connect. You should
explicitly specify the URL via devServer.public.
Access the dev server via http://localhost:<your container's external mapped port>http://localhost:8080/
Note that the development build is not optimized.
To create a production build, run npm run build.
Any ideas?
Thanks in advance!
My team had similar issues as you are describing. We could fix it by adding the optimization object to our Webpack config (vue.config.js`).
const {defineConfig} = require('#vue/cli-service');
module.exports = defineConfig({
/* your config */
configureWebpack: {
optimization: {
runtimeChunk: 'single',
},
},
devServer: {
// we need this for apollo to work properly
proxy: `https://${process.env.SANDBOX_HOSTNAME}/`,
host: '0.0.0.0',
allowedHosts: 'all',
},
});
The optimization part fixed the HMR for us. However, if you're using Firefox, your console might still be spammed by error messages like these:
The connection to wss://SANDBOX_HOSTNAME:8080/ws was interrupted while
the page was loading.
This has been a blocker of vue 3 for us, so I hope it helps. ✌️

How to use Cypress.env() inside Cypress/fixtures/sample.js file?

I have a sample.js file like this:
Cypress/fixtures/sample.js
module.exports = {
username: Cypress.env('username'),
password: Cypress.env('password')
}
and Cypress.json is like:
{
"baseUrl": "http://localhost:3000",
"video": false,
"viewportWidth": 375,
"viewportHeight": 812,
"defaultCommandTimeout": 10000,
"retries": {
"runMode": 2,
"openMode": 0
},
"env": {
"username": "******",
"password": "******"
}
}
But it doesn't works and returns:
Cypress is not defined!
You don't need to call it from fixtures. Cypress.env() are global varibales and can be access everywhere so no need of fixtures.
Simply call it like:
Cypress.env('username'),
Cypress.env('password')

Error while running "waitForElementVisible" command for Microsoft Edge on nightwatchj.s

When I trying run test in Microsoft edge
browser starting and page is loading, but then I got error :
TypeError: Error while running "waitForElementVisible" command: Error while trying to create HTTP request for "/wd/hub/session/8bf67432a94d18e24f88493fd249c629/element/[object Object]/displayed": Request path contains unescaped characters
For Chrome and Firefox test works fine
Test code
module.exports = {
'Demo test Ecosia.org': function (browser) {
browser
.url('https://www.ecosia.org/')
.waitForElementVisible('body')
.assert.titleContains('Ecosia')
.assert.visible('input[type=search]')
.setValue('input[type=search]', 'nightwatch')
.assert.visible('button[type=submit]')
.click('button[type=submit]')
.assert.containsText('.mainline-results', 'Nightwatch.js')
.end();
}
};
My nightwatch.conf.js
const seleniumServer = require('selenium-server');
const edgeDriver = require('edgedriver');
const chromeDriver = require('chromedriver');
const geckoDriver = require('geckodriver');
module.exports = {
src_folders: ['tests'],
custom_commands_path: '',
custom_assertions_path: '',
page_objects_path: '',
globals_path: '',
live_output: false,
disable_colors: false,
parallel_process_delay: 10,
"test_workers": {
"enabled": false,
"workers": "auto"
},
selenium: {
start_process: true,
//start_session: false,
server_path: seleniumServer.path,
check_process_delay: 5000,
host: '127.0.0.1',
port: 4144,
cli_args: {
"webdriver.ie.driver": ieDriver.path,
"webdriver.chrome.driver": chromeDriver.path,
"webdriver.gecko.driver": geckoDriver.path,
"webdriver.edge.driver": "node_modules/edgedriver_win64/msedgedriver.exe"
}
},
test_settings: {
skip_testcases_on_fail: false,
end_session_on_fail: false,
default: {
desiredCapabilities: {
browserName: 'chrome',
}
},
chrome: {
desiredCapabilities: {
browserName: 'chrome',
javascriptEnabled: true,
acceptSslCerts: true,
chromeOptions: {
w3c: false,
args: ['disable-gpu']
}
}
},
firefox: {
desiredCapabilities: {
browserName: 'firefox',
javascriptEnabled: true,
acceptSslCerts: true,
marionette: true,
}
},
edge: {
desiredCapabilities: {
browserName: 'MicrosoftEdge',
javascriptEnabled: true,
acceptSslCerts: true
}
},
}
};
As you're using the new Edge which is based on chromium, I think you can refer to the same setting of Chrome.
The same error occurs when using Chrome can be fixed by adding "w3c": false. So you could add the following line to fix issue in Edge Chromium:
edgeOptions: { "w3c": false }
Reference link: TypeError ERR_UNESCAPED_CHARACTERS on testing Vue project using Nightwatch

Resources