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')
Related
I have a nextjs project with a :client param which represents a client, like this:
domain.com/:client
And I have multiple clients... so I need to do this rewrite:
:client.domain.com -> domain.com/:client
For example for clients:
google.domain.com -> domain.com/google
netflix.domain.com -> domain.com/netflix
...
Inside the same project.
Any way to do that?
You can use the redirects option in the vercel.json, as Maxime mentioned.
However, it requires 1 extra key.
For example, if your app is available at company.com:
{
...
redirects: [
{
"source": "/",
"has": [
{
"type": "host",
"value": "app.company.com"
}
],
"destination": "/app"
}
]
}
More info:
Example Guide
vercel.json docs
Create a config in your project root with next.config.js
If this file exists add the following snippet to it, Mind you, we used example.com in place of domain .com as Body cannot contain "http://domain. com" in stackoverflow
// next.config.js
module.exports = {
async redirects() {
return [
{
source: "/:path*",
has: [
{
type: "host",
value: "client.example.com",
},
],
destination: "http://example.com/client/:path*",
permanent: false,
},
];
},
};
To confirm it's also working in development, try with localhost
module.exports = {
reactStrictMode: true,
// async rewrites() {
async redirects() {
return [
{
source: "/:path*",
has: [
{
type: "host",
value: "client.localhost",
},
],
destination: "http://localhost:3000/client/:path*",
permanent: false,
},
];
},
};
Dynamic Redirect
To make it dynamic, we'll create an array of subdomains
const subdomains = ["google", "netflix"];
module.exports = {
async redirects() {
return [
...subdomains.map((subdomain) => ({
source: "/:path*",
has: [
{
type: "host",
value: `${subdomain}.example.com`,
},
],
destination: `https://example.com/${subdomain}/:path*`,
permanent: false,
})),
];
},
}
You can read more from the official next.js doc redirects or rewrite
I've been trying to make a Firefox extension. I've had success with doing stuff after a user interaction (like a browser action). But I want my extension to do something without user interaction. But no matter what I do, I can't get anything to happen on page load. Here is my super reduced code:
manifest.json
{
"name": "Test",
"version": "0.1",
"manifest_version": 2,
"background": {
"scripts": ["test.js"]
}
}
test.js
document.addEventListener("DOMContentLoaded", init);
function init() {
document.body.innerHTML = "Hello world!";
}
What am I doing wrong here? It works in the toolbox, just not anywhere else!
I've also tried adding host permissons like this:
"permissions": [
"*://*.facebook.com/*"
],
Try this:
manifest.json
{
"name": "Test",
"version": "0.1",
"manifest_version": 2,
"background": {
"scripts": ["background.js"]
},
"permissions": ["webNavigation", "*://*.facebook.com/*"]
}
background.js
browser.webNavigation.onDOMContentLoaded.addListener(handleOnDOMContentLoaded, {
url: [{ hostEquals: 'www.facebook.com' }],
});
function handleOnDOMContentLoaded({ tabId }) {
browser.tabs.executeScript(tabId, { file: 'test.js' });
}
test.js
document.body.innerHTML = 'Hello world!';
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
I’m using AWS Cognito to perform login authentication. When login is successful we get below request body :
Request body:
> {"UserContextData":{"EncodedData":"eyJ..9”},”ClientMetadata":{"cognito:deviceName":"MacBookPro12-01","cognito:bundleShortV":"1.0.0",
> "cognito:idForVendor":"A6FD46FBB205","cognito:bundleVersion":"207",
> "cognito:bundleId":"com.abc.Project-Dev","cognito:model":"iPhone", "cognito:systemName":"iOS","cognito:iOSVersion":"11.3"},
> "AuthParameters":{"SRP_A":"a6..627","SECRET_HASH":"vr..Oo=", "USERNAME":"jay.dubey#abc.com”},**”AuthFlow":"USER_SRP_AUTH"**,
> "ClientId”:”123”}
Now, there is a scenario wherein I’ve to set “AuthFlow” value to “USER_PASSWORD_AUTH”. How can this be done?
The headache with this is that all these values are set in Pods. Below code prints the request body that is added above :
passwordAuthenticationCompletion?.set(result: AWSCognitoIdentityPasswordAuthenticationDetails(username: username, password: password))
If you will look into AWSCognitoIdentityUser in method getSessionWithUserName andPassword you will see that there is a ternary operator switching migration auth that is driven by migrationEnabled Boolean value. In order to switch auth type just configure identity pool like so:
let userPoolConfiguration = AWSCognitoIdentityUserPoolConfiguration (
clientId: clientId,
clientSecret: nil,
poolId: userPoolId,
shouldProvideCognitoValidationData: false,
pinpointAppId: nil,
migrationEnabled: true
)
I found you need to enable the migration in your amplifyconfigurqaton.json so that it uses the USER_PASSWORD_AUTH mode (it will ignore it otherwise):
{
"auth": {
"plugins": {
"awsCognitoAuthPlugin": {
"IdentityManager": {
"Default": {}
},
"CredentialsProvider": {
"CognitoIdentity": {
"Default": {
"PoolId": "xxxx",
"Region": "xxxxx"
}
}
},
"CognitoUserPool": {
"Default": {
"PoolId": "xxxxx",
"AppClientId": "xxxxx",
"Region": "xxxxx",
"MigrationEnabled" : true
}
I created a table with timestamps using sequelize. when I am updating the table, it automatically updates the timestamp (i.e createdAt and updatedAt). but these times are different from my local time. I have attached herewith 2 screenshots with the model script if I use moment to convert timezone like this useupdateddAt: moment().utc(new Date()) it works fine. is there a way to automatically update the timestamps with current timezone?
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.createTable('States', {
hashCode: {
type: Sequelize.STRING,
unique:true,
autoIncrement:false
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.dropTable('States');
}
};
when updateding the table
my local time in the pc
Create database like this you'll get automatically created at updated at according local time
const sequelize = new Sequelize("db_name", "username", "password",
{
logging: false,
host: "localhost",
dialect: "mysql",
dialectOptions: {
// useUTC: false, //for reading from database
dateStrings: true,
typeCast: true,
timezone: "+05:30"
},
timezone: "+05:30", //for writing to database
operatorsAliases: false
});
You should set the timezone property in sequelize options:
const sequelize = new Sequelize({
database: 'db_name',
username: 'username',
password: null,
dialect: 'mysql'
timezone: 'utc', // your timezone comes here, ex.: 'US/Hawaii'
});
I'm late but this works for me:
new Sequelize(db,user,pass, {timezone: "-05:00"}) where "-05:00" is offset time.
En
config.json too...
{
"development": {
"database": "db",
"username": "user",
"password": "pwd",
"logging": false, // verbose
"host": "localhost",
"dialect": "mysql",
"operatorsAliases": false,
"timezone": "-05:00"
},
"test": {
...
},
"production": {
...
}
}