I am trying to setup Nightwatch so that I do not have to use Selenium and instead point directly to an instance of Chrome on Linux, but I seem to be unable to connect to the chromedriver instance.
nightwatch.json
{
"src_folders" : ["tests"],
"output_folder" : "reports",
"custom_commands_path" : "",
"custom_assertions_path" : "",
"page_objects_path" : "",
"globals_path" : "globals.js",
"selenium" : {
"start_process" : false,
"cli_args" : {
"webdriver.chrome.driver" : "./chromedriver"
}
},
"test_settings" : {
"default" : {
"selenium_port" : 9515,
"selenium_host" : "127.0.0.1",
"silent": true,
"screenshots" : {
"enabled" : false,
"path" : ""
},
"desiredCapabilities": {
"browserName": "chrome",
"acceptSslCerts": true
}
}
}
}
After attempting to run a simple test suite, I get the following error
~/scripts/TestNightwatch$ nightwatch
[Test] Test Suite
=====================
Running: Demo test Google Error processing the server response:
unknown command: wd/hub/session
Error retrieving a new session from the selenium server
Connection refused! Is selenium server started? { value: -1, error:
'Unexpected token u in JSON at position 0' }
Have I not configured nightwatch properly to connect to Chrome? Am I missing any pieces of the puzzle?
Thanks in advance!
globals.js
var chromedriver = require('chromedriver');
module.exports = {
before : function(done) {
chromedriver.start();
done();
},
after : function(done) {
chromedriver.stop();
done();
}
}
The issue may be that Chromedriver is expecting commands at / instead of /wd/hub. To fix, start Chromedriver with --url-base=/wd/hub
Source: Selenium WebDriverJS, cannot build webdriver for Chrome and https://github.com/webdriverio/webdriverio/issues/113
You need to start chromedriver in your external globals file. It looks like your config is correct. Just setup your before and after functions in the external globals module to start chromedriver.
before : function(done) {
chromedriver.start();
done();
},
after : function(done) {
chromedriver.stop();
done();
}
Take a look at the Getting Started guide for more details.
Related
We are trying to connect an atoti cube the same way that is on env.js on the Active UI frontend.
window.env = {
contentServerVersion: "5.11.x",
contentServerUrl: "https://activepivot-ranch.activeviam.com:5110",
// WARNING: Changing the keys of activePivotServers will break previously saved widgets and dashboards.
// If you must do it, then you also need to update each one's serverKey attribute on your content server.
activePivotServers: {
// You can connect to as many servers as needed.
// In practice most projects only need one.
"Ranch 5.11": {
url: "https://activepivot-ranch.activeviam.com:5110",
version: "5.11.1",
},
"Ranch 5.10": {
url: "https://activepivot-ranch.activeviam.com:5100",
version: "5.10.0",
},
"Ranch 5.9": {
url: "https://activepivot-ranch.activeviam.com:5900",
version: "5.9.4",
},
"my-server": {
url: "https://localhost:9090",
version: "5.10.x",
}
},
};
but when we launch the frontend we are just give this error: 404: The resource at http://localhost:9090/atoti/pivot/rest/v5/ping was not found.
The URL in your env.js is probably not correct. You can find the correct one by running the following in your notebook:
session.link()
Let's call what it returns my-url.
Then your env.js should look like this:
window.env = {
contentServerVersion: "5.10",
contentServerUrl: my-url,
activePivotServers: {
"my-server": {
url: my-url,
version: "5.10",
},
},
};
You might also have to change your version attribute. It depends on your atoti version, as follows:
atoti 0.6.x => version = "5.11.0"
atoti 0.5.x => version = "5.10.0"
atoti 0.2.x, 0.3.x, 0.4.x => version = "5.9.0"
earlier => version = "5.8.0"
I just recently started working with Karma runner in our UI5 app. Wrote some unit tests, ran them... all worked fine so far.
However, now I´ve decided to track the code coverage. To measure it, I need to run preprocessor on my source code. And this is where I stumbled upon a problems - I am currently trying to make it work and both have some kind of problems
npm package karma-coverage as a preprocessor - after installing it, I set it up in karma.conf.js like this
preprocessors: {
"webapp/helpers/**/*.js": ['coverage'],
"webapp/controller/**/*.js": ['coverage'],
},
This works fine on helpers folder since it contains only one file with simple javascript. However, when it tries to process controller folder which has files with some ES6 code, each file fails with errors such as these
Unexpected token function
Unexpected token ...
As a second option, I tried to use karma-babel-preprocessor which should be able to handle also ES6 code. This is how my karma.conf.js file looks like
preprocessors: {
"webapp/helpers//.js": ['babel'],
"webapp/controller//.js": ['babel'],
},
babelPreprocessor: {
options: {
presets: ['#babel/preset-env'],
sourceMap: 'inline'
} ,
filename: function (file) {
return file.originalPath.replace(/\.js$/, '.es5.js');
},
sourceFileName: function (file) {
return file.originalPath;
}
},
However, this one is not even able to find the js file (even though the address is the same as in the case of coverage preprocesor) and returns this error.
Error: failed to load 'sbn/portal/helpers/formatter.js' from .webapp/helpers/formatter.js: 404 - Not Found
at https://openui5.hana.ondemand.com/resources/sap-ui-core.js:86:37
Does someone have an idea how I can get the coverage data while using these packages or any other ones? There is a lots of conflicting info on the web, most of it several years old while various karma-related npm packages keep popping up each month so I am really not sure which one would be the best to use.
Thank a lot
We had the same problem and we managed to fix it integrating babel in a ui5-building-tool step.
This is how our package.json looks like:
{
"devDependencies": {
"babel-core": "6.26.3",
"babel-plugin-fast-async": "6.1.2",
"babel-preset-env": "1.7.0",
"karma": "^4.0.1",
"karma-chrome-launcher": "^2.2.0",
"karma-coverage": "^1.1.2",
"karma-ui5": "^1.0.0",
"karma-junit-reporter": "1.2.0",
"rimraf": "^2.6.2",
"start-server-and-test": "^1.4.1",
"#ui5/cli": "^1.5.5",
"#ui5/logger": "^1.0.0",
}
"scripts": {
"start": "ui5 serve -o index.html",
"lint": "eslint webapp",
"test": "karma start",
"build": "npm run test && rimraf dist && ui5 build --a --include-task=generateManifestBundle"
}
}
This is how the ui5.yaml is looking like
specVersion: '1.0'
metadata:
name: app-name
type: application
builder:
customTasks:
- name: transpile
afterTask: replaceVersion
---
specVersion: "1.0"
kind: extension
type: task
metadata:
name: transpile
task:
path: lib/transpile.js
This is how the transpile.js is looking like:
Be aware that this file should be placed in the root-dir/lib folder. root-dir is the folder where ui5.yaml is residing.
const path = require("path");
const babel = require("babel-core");
const log = require("#ui5/logger").getLogger("builder:customtask:transpile");
/**
* Task to transpiles ES6 code into ES5 code.
*
* #param {Object} parameters Parameters
* #param {DuplexCollection} parameters.workspace DuplexCollection to read and write files
* #param {AbstractReader} parameters.dependencies Reader or Collection to read dependency files
* #param {Object} parameters.options Options
* #param {string} parameters.options.projectName Project name
* #param {string} [parameters.options.configuration] Task configuration if given in ui5.yaml
* #returns {Promise<undefined>} Promise resolving with undefined once data has been written
*/
module.exports = function ({
workspace,
dependencies,
options
}) {
return workspace.byGlob("/**/*.js").then((resources) => {
return Promise.all(resources.map((resource) => {
return resource.getString().then((value) => {
log.info("Transpiling file " + resource.getPath());
return babel.transform(value, {
sourceMap: false,
presets: [
[
"env",
{
exclude: ["babel-plugin-transform-async-to-generator", "babel-plugin-transform-regenerator"]
}
]
],
plugins: [
[
"fast-async",
{
spec: true,
compiler: {
"promises": true,
"generators": false
}
}
]
]
});
}).then((result) => {
resource.setString(result.code);
workspace.write(resource);
});
}));
});
};
And finally this is the karma.conf.js setup:
module.exports = function (config) {
var ui5ResourcePath = "https:" + "//sapui5.hana.ondemand.com/resources/";
config.set({
// the time that karma waits for a response form the browser before closing it
browserNoActivityTimeout: 100000,
frameworks: ["ui5"],
// list of files / patterns to exclude
exclude: [],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
"root_to_to_files/**/*.js": ["coverage"],
},
// test results reporter to use
// possible values: "dots", "progress"
// available reporters: https://npmjs.org/browse/keyword/karma-reportery
reporters: ["progress", "coverage"],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ["Chrome"],
// Continuous Integration modey
// if true, Karma captures browsers, runs the tests and exits
singleRun: true,
// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity,
// generates the coverage report
coverageReporter: {
type: "lcov", // the type of the coverage report
dir: "reports", // the path to the output directory where the coverage report is saved
subdir: "./coverage" // the name of the subdirectory in which the coverage report is saved
},
browserConsoleLogOptions: {
level: "error"
}
});
};
In our project this setup works fine with ES6 code and prints the coverage.
Hope this you help you. Please give me a feedback how this works.
I am currently building my first Angular 5 application that has to interact with my Java Rest Web Services that I built using [Spring Boot]
(https://www.javatpoint.com/spring-boot-tutorial).
I wrote my first HTTP connection by following various tutorials. My goal is to perform a POST; I did the following:
I created a file called proxy-config.json [web services are obtainable in localhost:8080]:
{
"/*": {
"target": "http://localhost:8080",
"changeOrigin": true,
"secure": false,
"logLevel": "info"
}
}
And edited the start line in package.json to:
"start": "ng serve --proxy-config proxy-config.json",
I then wrote a http-post in a save-data.component.ts file [logMe() is a button click event]:
logMe() {
let body = JSON.stringify({ "userEmail": this.userEmail, "userPassword": this.userPassword} );
this.http.post('/logging', body, httpOptions).subscribe(
data => {
console.log( data );
},
error => {
console.error("There Is Something Wrong\nPlease Try Again Later...");
}
);
console.log ( body );
}
The problem is that, when I send the post I receive the following
error on the browser's console:
POST http://localhost:4200/logging 404 (Not Found)
Can you try with this one?
{
"/api": {
"target": "http://localhost:8080",
"secure": false,
"pathRewrite": {"^/api" : ""}
}
}
Also, make sure proxy-config.json is in root folder
I have pm2 running my node app, and was wondering if I can make sure it is reloading with zero downtime on the watch, rather than just restarting. Here is a sample json file that is setup how I am using pm2.
{
"name" : "server",
"cwd" : "/home/user/website",
"script" : "server/server.js",
"instances" : 2,
"max_restarts" : 0,
"watch" : true,
"ignore_watch" : ["some/files"],
"env_staging": {
"NODE_ENV": "staging"
},
"env_production": {
"NODE_ENV": "production"
}
}
nope, got the same problem, according to the documentation and source code, this is not possible
I'm using:
Elasticsearch 2.3
Watcher
Topbeat
The goal is to create a watch that every x amount of time does a query and retrieves some hits, and post it to a web server. This works fine. However, the Json response in {{ctx.payload.hits.hits}} isn't Json, so I can't proccess it. The same issue seems to appear in some threads, this being the most similar to mine:
So, this is my watch (the input works fine, the issue is in the script of the action):
PUT _watcher/watch/running_process_watch
{
"trigger" : {
"schedule" : {
"interval" : "10s"
}
},
"input" : {... },
"actions" : {
"ping_webhook": {
"transform":{
"script": "return [ body: groovy.json.JsonOutput.toJson(ctx.payload.hits.hits)]"
},
"webhook": {
"method": "POST",
"host": "localhost",
"port": 4567,
"path": "/register_data",
"headers": {
"Content-Type" : "application/json"
},
"body" : "data: {{ctx.payload.body}}"
}
}
}
}
The error:
failed to execute [script] transform for [running_process_watch_0-2016-06-08T17:25:14.162Z]
ScriptException[failed to run inline script [return [ body: groovy.json.JsonOutput.toJson(ctx.payload.hits.hits)]] using lang [groovy]]; nested: MissingPropertyException[No such property: groovy for class: 1605d064acb49c10c464b655dacc9193f4e2e484];
at org.elasticsearch.script.groovy.GroovyScriptEngineService$GroovyScript.run(GroovyScriptEngineService.java:320)
at org.elasticsearch.watcher.transform.script.ExecutableScriptTransform.doExecute(ExecutableScriptTransform.java:74)
at org.elasticsearch.watcher.transform.script.ExecutableScriptTransform.execute(ExecutableScriptTransform.java:60)
at org.elasticsearch.watcher.transform.script.ExecutableScriptTransform.execute(ExecutableScriptTransform.java:41)
at org.elasticsearch.watcher.actions.ActionWrapper.execute(ActionWrapper.java:94)
at org.elasticsearch.watcher.execution.ExecutionService.executeInner(ExecutionService.java:388)
at org.elasticsearch.watcher.execution.ExecutionService.execute(ExecutionService.java:273)
at org.elasticsearch.watcher.execution.ExecutionService$WatchExecutionTask.run(ExecutionService.java:438)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Any idea to make groovy.json usable inside the watcher action script? Or any other idea to return proper json from the ctx.hits.hits?
So, I opened an issue in Elasticsearch repo. After some discussion, a native toJson function is going to be implemented in the mustache templating engine so it renders json by default.
Here is the pull request.
Hopefully in the next release will be ready.