Currently we have a "standard" protractor.conf.js file in place. It has a chrome specific section which looks something like this:
capabilities: {
browserName: 'chrome',
chromeOptions: {
args: [
'--no-sandbox', '--window-size=1280,1480', '--window-position=800,0'
],
prefs: {
intl: {accept_languages: defaults.LANGUAGE},
},
},
}
When we run the tests locally, everything is fine.
On our CI Infrastructure we add via CLI call the headless option:
protractor protractor.conf.js --capabilities.chromeOptions.args='headless'
First everything looked fine. The tests were running with headless chrome. But we recognized that the --window-size=1280,1480 specified in the config file was not used. We removed the --capabilities from the cli call and added the headless option directly into the protractor.conf.js.
Everything was now also working fine on the CI Infrastructure. This means the --window-size specified in the config was recognized and used.
Further tests showed, that if we want to use the CLI arguments, we would need to also add the window-size to the CLI call, to get it working as it should.
Now the question itself:
Why is this like that ? Shouldn't it be possible to add additional chromeOptions.args via CLI call ? Are the chromeOptions.args from the config no longer respected when passing some chromeOptions.args via CLI ?
Yes, The CLI values will overwrite the value in conf.js.
Below is the code snippet from launcher.ts
let initFn = function(configFile: string, additionalConfig: Config) {
let configParser = new ConfigParser();
if (configFile) { // this is the protractor conf.js
configParser.addFileConfig(configFile);
}
if (additionalConfig) { // this is all cli arguments
configParser.addConfig(additionalConfig);
}
Below is the addConfig from configParser.ts
public addConfig(argv: any): ConfigParser {
this.addConfig_(argv, process.cwd());
return this;
}
private addConfig_(additionalConfig: any, relativeTo: string): void {
// All filepaths should be kept relative to the current config location.
// This will not affect absolute paths.
['seleniumServerJar', 'chromeDriver', 'firefoxPath', 'frameworkPath', 'geckoDriver',
'onPrepare']
.forEach((name: string) => {
if (additionalConfig[name] && typeof additionalConfig[name] === 'string') {
additionalConfig[name] = path.resolve(relativeTo, additionalConfig[name]);
}
});
merge_(this.config_, additionalConfig);
}
let merge_ = function(into: any, from: any): any {
for (let key in from) {
if (into[key] instanceof Object && !(into[key] instanceof Array) &&
!(into[key] instanceof Function)) {
merge_(into[key], from[key]);
} else {
into[key] = from[key];
}
}
return into;
};
Because capabilities.chromeOptions.args is Array, thus the args value in conf.js will be overwrite by value from cli in merge_ function: into[key] = from[key];
Therefor, you have to specify all chromeOptions.args from cli by using multiple --capabilities.chromeOptions.args=xxx in cli, rather than
partial.
protractor conf.js \
--capabilities.chromeOptions.args='headless' \
--capabilities.chromeOptions.args='--no-sandbox' \
--capabilities.chromeOptions.args='--window-size=1280,1480'
Related
Here is my code:
import { Map as LeafletMap, TileLayer } from 'react-leaflet';
function Map() {
return (
<div className="map">
<LeafletMap>
<TileLayer
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
attribution='© OpenStreetMap contributors'/>
</LeafletMap>
</div>
But I got an error saying Attempted import error: 'Map' is not exported from 'react-leaflet' (imported as 'LeafletMap'). I've tried changing the 'import { Map' to 'import { MapContainer' but still won't work. Instead I got another error saying:
./node_modules/#react-leaflet/core/esm/path.js 10:41
Module parse failed: Unexpected token (10:41)
File was processed with these loaders:
* ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
| useEffect(function updatePathOptions() {
| if (props.pathOptions !== optionsRef.current) {
> const options = props.pathOptions ?? {};
| element.instance.setStyle(options);
| optionsRef.current = options;
I also tried changing the react-leaflet version from ^3.2.1 to ^2.7.0 and leaflet from ^1.7.1 to ^1.6.0. But still no luck. Any solutions?
You'll have to explicitly transpile react-leaflet because the maintainer is not understanding they should change their transpilation target to a lower version in order to more fully support the nullish coalescing operator: https://github.com/PaulLeCam/react-leaflet/issues/877#issuecomment-841871904
You can try adding this to your babel config
{
"plugins": ["#babel/plugin-proposal-nullish-coalescing-operator"]
}
And then make sure you transpile node_modules/react-leaflet during your build. If you are already using #babel/preset-env then you only need to make sure you're transpiling react-leaflet during the build. If you're using webpack you can do something like
module: {
rules: [
{
test: /\.jsx?$/,
exclude: filename => {
return /node_modules/.test(filename) && !/react-leaflet/.test(filename)
},
use: ['babel-loader']
}
]
}
I'm attempting to port an existing Functions app from core3.1 v3 to net5.0 I but can't figure out how to get the IOptions configuration pattern to work.
The configuration in my local.settings.json is present in the configuration data, and I can get to it using GetEnvironmentVariable. Still, the following does not bind the values to the IOptions configuration like it used to.
.Services.AddOptions<GraphApiOptions>()
.Configure<IConfiguration>((settings, configuration) => configuration.GetSection("GraphApi").Bind(settings))
The values are in the local.settings.json just as they were before:
"GraphApi:AuthenticationEndPoint": "https://login.microsoftonline.com/",
"GraphApi:ClientId": "316f9726-0ec9-4ca5-8d04-f39966bebfe1",
"GraphApi:ClientSecret": "VJ7qbWF-ek_Amb_e747nXW-fMOX-~6b8Y6",
"GraphApi:EndPoint": "https://graph.microsoft.com/",
"GraphApi:TenantId": "NuLicense.onmicrosoft.com",
Is this still supported?
What am I missing?
I had the same issue, but turns out that the json was not correctly formatted.
Just for reference, here it is how I configured it:
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureServices(s =>
{
s.AddOptions<ApplicationSettings>().Configure<IConfiguration>((settings, configuration) =>
{
configuration.GetSection(nameof(ApplicationSettings)).Bind(settings);
});
})
.Build();
And here is an example of local.setting.json:
{
"IsEncrypted": false,
"Values": {
"ApplicationSettings:test": "testtest",
"ApplicationSettings:testtest": "test"
}
}
As a part of Automation testing, I want to point my Testcafe tests to a Test Prod server (Green) with the help of Custom Headers.
How can I pass custom headers to chrome instance while launching to perform tests as arguments.
Tried chrome:userProfile but the headers change for every release.
Require a generic way to pass custom headers.
Note: Testcafe script changes are not preferable.
Google Chrome doesn't allow setting request headers from the command line, but you can use the request hook to add a header value based on the environmental variable.
Please refer to the following example. Note that RequestLogger was added only for demonstration purposes:
// test.js
import { RequestLogger, RequestHook } from 'testcafe';
fixture `Set a Custom Referer`
.page`http://example.com/`;
export class MyRequestHook extends RequestHook {
constructor(requestFilterRules, responseEventConfigureOpts) {
super(requestFilterRules, responseEventConfigureOpts);
}
async onRequest(event) {
event.requestOptions.headers['CustomHeader'] = process.env.HEADER_VALUE;
}
async onResponse(event) {
}
}
const hook = new MyRequestHook();
const logger = RequestLogger(
["https://devexpress.github.io/testcafe/example/", "http://example.com/"],
{
logRequestHeaders: true,
}
);
test
.requestHooks([hook, logger])
('Check the Referer Value', async t => {
await t
.navigateTo('https://devexpress.github.io/testcafe/example/')
.expect(logger.contains(r => r.request.url === 'https://devexpress.github.io/testcafe/example/')).ok()
.expect(logger.requests[0].request.headers['CustomHeader']).eql(process.env.HEADER_VALUE);
});
Now, you can run tests on the test server with the following command (POSIX):
export HEADER_VALUE='my value'
testcafe chrome test.js
Please refer to this documentation topic for more information: Create a Custom Request Hook.
I have a question, that's how to pass "--node-args" arguments in PM2 while using json config mode, like this:
pm2 start --node-args="--debug=5858" myPm2Config.json
well, I know I can write the arguments into myPm2Config.json file, but I dont want to do this, because I want to make two startup command as "debug" and "production" mode for launch application, such as "pm2_run" and "pm2_debug", and "pm2_debug" command with --node-args argument and "pm2_run" not, and I dont want to make two "myPm2Config.json" files, because that means if something needs changed, I will need to change two json config files, so, is there any easy way to do it? thanks guys!
I have found the solution! that's use js config instead of json config.
first, I create a pm2.config.js file. (mark: file name must be end with .config.js)
//[pm2.config.js]
let config = {
apps : [{
name : "node_shells",
script : "./bin/www",
log_date_format : "YYYY-MM-DD HH:mm:SS",
log_file : "logs/pm2.log",
error_file : "logs/pm2-err.log",
out_file : "logs/pm2-out.log",
pid_file : "logs/pm2.pid",
watch : true,
ignore_watch : ["logs/*", "node_modules/*", "uploads/*"]
}]
}
let debug_mode = false;
for(let arg of process.argv) {
if(arg == '-debug') {
debug_mode = true;
break;
}
}
if(debug_mode) {
console.log('== launching in debug mode ==');
config.apps[0].node_args = "--debug=5858";
}
else {
console.log('== launching in production mode ==');
config.apps[0].node_args = " "; //*require! or it will always uses latest debug options
}
module.exports = config;
then, create two launch files: "pm2_run" and "pm2_debug".
#[pm2_run]
pm2 start pm2.config.js
#[pm2_debug]
pm2 start pm2.config.js -- -debug
now, it's easy to switch debug mode or production mode!
I have a Play 2.0 application with 3 different configurations (application.conf, test.conf and prod.conf)
Now I have a robots.txt file that should be delivered for only test.conf and for the rest environments it should give a 404 if someone tries to access it.
How can I configure my routes file to check if my application is using test.conf? Can I set some variable in test.conf that I can check in the routes file?
Something like this? (pseudo code)
#{if environment = "test"}
GET /robots.txt controllers.Assets.at(path="/public", file="robots.txt")
#{/if}
#{else}
GET /robots.txt controllers.Application.notFoundResult()
#{/else}
You can't add logic in the routes file.
I'd write a controller to serve the robots.txt file. Something like this:
In the routes file:
GET /robots.txt controllers.Application.robots
Then, in the controller, I'll test if I'm in a testing environment :
def robots = Action {
if (environment == "test") { // customize with your method
Redirect(routes.Assets.at("robots.txt"))
} else {
NotFound("")
}
}
I'm using Scala, but it can be easily translated to Java.
Edit - java sample
You can check if application is in one of three states: prod, dev or test, ie, simple method returning current state:
private static String getCurrentMode() {
if (play.Play.isTest()) return "test";
if (play.Play.isDev()) return "dev";
if (play.Play.isProd()) return "prod";
return "unknown";
}
you can use as:
play.Logger.debug("Current mode: "+ getCurrentMode());
of course in your case that's enough to use these condition directly:
public static Result robots() {
return (play.Play.isProd())
? notFound()
: ok("User-agent: *\nDisallow: /");
}