I would like to implement CI/CD with UI tests I've written to automatically run my Nightwatch.js test on a nightly basis. I've tried copying my files to a workspace in jenkins and running them. I've tried using TFS as a version control system to see if we could get it to run that way. The problem I keep running into (see attached) is that when I run locally the chrome browser opens and runs the tests just fine. In Jenkins, however, It says that it can't find the element. I've researched how to run chrome headlessly but I still get the same error when I add the --headless tag to my nightwatch.json config file. Bottom line, How can I get Nightwatch.js tests to run on a nightly schedule? (preferably in jenkins)
Tried running tests from tfs source control
tried running tests from local tests copied to jenkins workspace.
tried running headless tests (locally works, Jenkins does not)https://developers.google.com/web/updates/2017/04/headless-chrome
Here is my nightwatch.json file.
{
"src_folders" : ["tests"],
"output_folder" : "reports/XMLReports",
"custom_commands_path" : "",
"custom_assertions_path" : "",
"page_objects_path" : "dealer",
"globals_path" : "",
"test_workers": false,
"selenium": {
"cli_args": {
"webdriver.chrome.driver" : "node_modules/.bin/chromedriver.cmd",
"webdriver.gecko.driver" : "node_modules/.bin/geckodriver.cmd",
"webdriver.edge.driver" : "node_modules/.bin/edgedriver.cmd"
},
"log_path": "",
"port": 4460,
"server_path": "lib/drivers/selenium-server-standalone-3.141.59.jar",
"start_process": true
},
"test_settings" : {
"chrome" : {
"launch_url" : "http://localhost",
"selenium_port" : 4460,
"selenium_host" : "127.0.0.1",
"silent": true,
"screenshots" : {
"enabled" : false,
"path" : "screenshots/Chrome/"
},
"desiredCapabilities": {
"browserName": "chrome",
"chromeOptions":{
"args": [
"disable-web-security",
"ignore-certificate-errors",
"--test-type",
"--disable-gpu",
"--headless",
"--remote-debugging-port=9222"
]
}
}
},
"edge" : {
"desiredCapabilities": {
"browserName": "MicrosoftEdge"
}
}
}
}
I would expect my tests to run in jenkins normally and give me a detailed report if it passed or failed in the ui.
It looks like the .windowMaximize() was causing my tests to hang and fail in Jenkins.
Related
I have an Angular web app, and a backend Node JS API, both hosted on Azure in Web Apps. I have used postman to verify that the API is running correctly. My local Dev version of the Angular app also currently points at the live API, and the requests work as expected. However, the deployed Angular App only returns 404's when making requests to the API.
I have the following proxy.confg.json:
{
"/api/*" : {
"target" : "https://{domain}.azurewebsites.net",
"pathRewrite": {
"^/api" : ""
},
"secure": false,
"changeOrigin": true,
"logLevel": "debug"
}
I have configured the proxy for use in production builds in angular.json as follows:
"serve": {
"builder": "#angular-devkit/build-angular:dev-server",
"configurations": {
"production": {
"browserTarget": "{project}:build:production",
"proxyConfig" : "proxy.conf.json"
}
When running locally using the proxy.confg.json (both "ng serve" and "ng serve --configuration production", API requests work as expected. However, the live app gives me the following two errors in the browser console:
XHR GET https://{domain}.azurewebsites.net/api/getData
Object { headers: {…}, status: 404, statusText: "Not Found", url: "https://{domain}.azurewebsites.net/api/getData", ok: false, name: "HttpErrorResponse", message: "Http failure response for https://{domain}.azurewebsites.net/api/getData: 404 Not Found", error: "The resource you are looking for has been removed, had its name changed, or is temporarily unavailable." }
Thanks # Penleychan your comments helped lot.
When you try to deploy dev to production environment you have to configure environment specific defalts
Angular project src/environments/ folder contains the base configuration file, environment.ts, which provides a default environment. You can add override defaults for additional environments, such as production (environment.prod.ts) and staging(environment.stage.ts), in target-specific configuration files.
In your environment.prod.ts environment file you can add your default environment values
export const environment = {
production: true,
apiUrl: 'http://my-prod-url'
};
use the environment configurations in your components you need to import the original environments file:
import { environment } from './../environments/environment';
Configure target-specific file replacement. By default no files are replaced. You can add file replacements for specific build targets in angular.json``:
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
...
If you are using the serve command to use the targeted build configuration.Add it to the "serve:configurations" section of angular.json:
"serve": {
"builder": "#angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "your-project-name:build"
},
"configurations": {
"production": {
"browserTarget": "your-project-name:build:production"
}
}
},
Which you are already done it. So once you added the Environment specific config you can fix the issue
Refer here
I am trying to access the environment variables set in a task definition, inside my nodejs app, with process.env.
I use a Dockerfile to create an image of the project, upload it to ECR, then use this image in the task definition.
I set enviroment variables for the nodejs app, inside the Dockerfile, like this:
# Dockerfile
...
RUN ROOT_DIR='/'
RUN PUBLIC_DIR='/public'
...
I have this task definition:
# task_definition.json
...
"environment" : [
{ "name" : "KeyOne", "value" : "KeyOneValue" },
{ "name" : "KeyTwo", "value" : "KeyTwoValue" }
]
...
I am not able to access process.env.KeyOne / process.env.KeyTwo (they are undefined)
I would like to be able to set those environment variables from the task definition and then reference them inside nodejs app with process.env instead of setting them inside the Dockerfile.
Here is a test I just made on my account, using ECS Fargate. All env variables from the task definition are accessible from NodeJS code.
Source Code is at
https://github.com/sebsto/ecs-demo/tree/master/so
TaskDefinition excerpt :
"environment": [
{
"name": "KEY1",
"value": "VALUE1"
}
],
Code extract :
app.get('/', (req, res) => {
res.send(`Hello world<br/>${JSON.stringify(process.env, null, 2)}`);
});
Output :
Hello world
{ "KEY1": "VALUE1", "NODE_VERSION": "10.16.0", "HOSTNAME": "ip-10-0-0-83.eu-west-1.compute.internal", "YARN_VERSION": "1.16.0", "HOME": "/root", "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI": "/v2/credentials/b630982f-dffb-4ccc-9c8b-8311e42b57ab", "AWS_EXECUTION_ENV": "AWS_ECS_FARGATE", "AWS_DEFAULT_REGION": "eu-west-1", "ECS_CONTAINER_METADATA_URI": "http://169.254.170.2/v3/12186f93-de7b-47e3-a096-b0f23d7e0e81", "PATH": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "AWS_REGION": "eu-west-1", "PWD": "/usr/src/app" }
I'll keep the container is up and running for a few months, you can test yourself at http://52.18.232.75:8080/
I want to write the actual test output of NightwatchJS tests (not the browser console) to a file. I can't seem to find any resource regarding about this.
The log_path option is ok, it does log some stuff on the location you specified after the test, but its not the same data vs the actual test output.
below is my nightwatch.json file
{
"src_folders" : [
"tests" ,
"tests/settings/general"
],
"page_objects_path" : [
"page_objects/backend" ,
"page_objects/frontend" ,
"page_objects/backend/settings/general"
],
"globals_path" : "./nightwatch.globals.js",
"webdriver" : {
"start_process" : true,
"log_path" : "./logs"
},
"test_settings" : {
"default" : {
"webdriver": {
"server_path" : "node_modules/.bin/chromedriver",
"port" : 9515,
"cli_args" : [ "--log" , "debug" ]
},
"desiredCapabilities": {
"browserName" : "chrome",
"acceptInsecureCerts" : true,
"javascriptEnabled" : true,
"acceptSslCerts" : true
}
},
"firefox" : {
"webdriver": {
"server_path" : "node_modules/.bin/geckodriver",
"port" : 4444,
"cli_args" : [ "--log" , "debug" ]
},
"desiredCapabilities": {
"browserName" : "firefox",
"acceptInsecureCerts" : true,
"javascriptEnabled" : true,
"acceptSslCerts" : true
}
}
}
}
Hope you can help me on this.
Thanks in advance.
You could add '> tests_output/Test_filename.txt' after the command to run the test. So, I have my package.json file set up with the script 'test' for running Nightwatch. My terminal input to save the output as a file would look like this:
npm test > /tests_output/testRun100720.txt
This will place the output file I name testRun100720.txt into the tests_output folder.
Can you provide a little more detail of what you mean by 'output'?
In the meantime, try adding "output_folder": "reports/", to your json file, this should generate XML output from the Nightwatch logger which may provide more details.
I'm on a windows 10 environment writing a plugin for the Atom text editor to allow running tests through protractor cucumber from within atom it consumes the PlatformIO-Terminal plugin's provided service. When I activate that terminal plugin from within Atom I'd expect to be able to execute any old program from it that I could from my terminal that it's emulating through pty.
I'm having trouble executing any node program I've installed via npm outside of Atom's apm. Further digging via printing the environment variable NODE_PATH from within that terminal revealed that Atom has eaten my NODE_PATH value, not appended it's own but completely consumed and replaced it. Resetting it from within that pty window doesn't work, and neither does adding it to the "Shell Environment Variables" from within the PlatformIO configuration terminal. I've installed 3 plugins which allow pulling in environment variables from the OS, and none of them have succeeded.
Is there a way to solve this problem? I can access the executable modules directly, but they call other ones and depend on NODE_PATH.
If you aren't having success with terminal packages, you might try process-palette. It allows you to precisely define all of the details of the command, including environment variables. I've made an Atom command that sets NODE_ENV to an arbitrary string before executing a terminal command. Screenshots below:
Below is a process-palette.json file that defines the command I wrote. All you have to do to get started is install the package, make that file with the following code, and select Packages -> Process Palette -> Edit Configuration.
{
"patterns": {
"P1": {
"expression": "(path):(line)"
},
"P2": {
"expression": "(path)\\s+(line)",
"path": "(?:\\/[\\w\\.\\-]+)+"
}
},
"commands": [
{
"namespace": "process-palette",
"action": "env",
"command": "echo %NODE_PATH%",
"arguments": [],
"cwd": null,
"inputDialogs": [],
"env": {
"NODE_PATH": "wargarble"
},
"keystroke": null,
"stream": true,
"outputTarget": "panel",
"outputBufferSize": 80000,
"maxCompleted": 3,
"autoShowOutput": true,
"autoHideOutput": false,
"scrollLockEnabled": false,
"singular": false,
"promptToSave": true,
"saveOption": "none",
"patterns": [
"default"
],
"successOutput": "{stdout}",
"errorOutput": "{stdout}\n{stderr}",
"fatalOutput": "Failed to execute : {fullCommand}\n{stdout}\n{stderr}",
"startMessage": null,
"successMessage": "Executed : {fullCommand}",
"errorMessage": "Executed : {fullCommand}\nReturned with code {exitStatus}\n{stderr}",
"fatalMessage": "Failed to execute : {fullCommand}\n{stdout}\n{stderr}",
"menus": [
"env"
],
"startScript": null,
"successScript": null,
"errorScript": null,
"scriptOnStart": false,
"scriptOnSuccess": false,
"scriptOnError": false,
"notifyOnStart": false,
"notifyOnSuccess": true,
"notifyOnError": true,
"input": null
}
]
}
I trying to run sync gateway code into the terminal but i don't understand how it works, even through needless response. see the code below,
{
"log": ["HTTP+"],
"databases": {
"grocery-sync": {
"server": "http://localhost:8091",
"bucket": "grocery-sync",
"users": {
"GUEST": {"disabled": false, "admin_channels": ["*"] }}}}
}
But,i getting below response but i couldn't understand what exactly need to do for auto replication.