question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

passing username / password dynamically (CLI or other workaround)

See original GitHub issue

We are testing an add-in (plugin if you will) that is running inside another webapp (Outlook Web Access). To authenticate, we either use our own account (when developing) or specific test accounts (QA’s / automated testing).

However, we wish to nót hardcode the account details (so not hardcoded inside an exported module and not using a DataTable, etc.) but pass them via the command line. For example, using protractor, something like this is quite trivial, as you can just create a config object that contains the fields username and password and overwrite these with separate flags using the CLI.

It seems this is a lot harder to achieve in Codecept. I know of the --profile switch, but it seems like a hassle to make that work for multiple fields (like username + password). Another approach I tried was to set process environment variables befóre running tests witha simple node script that prompts for username and password if these are not set. However, I can not retrieve these inside my tests:

excerpt from e2e-credentials.js:

process.env.OWA_CODECEPT_USER = username;
process.env.OWA_CODECEPT_PASS = password;

package.json script: "test:e2e:verbose": "node tools/e2e-credentials.js && codeceptjs run --steps --debug --verbose",

`CodeceptJs test:

loginToOwaPage.login(process.env.OWA_CODECEPT_USER, process.env.OWA_CODECEPT_PASS);

But this does not work, probably because these are not the same processes?

What would be the best way to achieve such a thing in CodeceptJs ?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
austinmehmetcommented, Apr 15, 2019

We had to do something similar because we needed to pass in dynamic environments generated by our CI and run against a proxy username/password. This is all done through the CLI and we have different scripts that run locally vs in our CI/CD all with different credentials.

codecept.conf.js

const config = {
  // your config
}

// check if you have env variables
if (process.env.npm_config_proxyusername !== undefined && process.env.npm_config_proxypassword !== undefined) {
  // set the username/password into a custom helper
  config.helpers.LaunchHelper.username = process.env.npm_config_proxyusername
  config.helpers.LaunchHelper.password = process.env.npm_config_proxypassword
}

custom LaunchHelper

class LaunchHelper extends Helper {
  async launchApplication() {
    const I = actor()

    I.amOnPage('/')
    if (this.config.username && this.config.password) {
      const puppeteer = this.helpers.Puppeteer
      const page = await puppeteer.page
      await page.authenticate({ username: this.config.username, password: this.config.password })
    }
  }
}

module.exports = LaunchHelper

example script

npm run e2e:headless --url="$CI_ENVIRONMENT_URL" --proxyusername="$proxy_username" --proxypassword="$proxy_password"
1reaction
gabrielcairescommented, Mar 7, 2019

You can use .env file with this package https://www.npmjs.com/package/env-cmd. So, you will just need to update your package.json to use something like: env-cmd .env.test codeceptjs run

Read more comments on GitHub >

github_iconTop Results From Across the Web

passing username / password dynamically (CLI or ... - GitHub
So right now, my solution is a (git) ignored credentials.js file, but I find this a workaround and not a solution.
Read more >
Is there a way to pass credentials dynamically while executing ...
Is there a way to pass these json variables dynamically in a single run command, like: op create item login $(op get template...
Read more >
Is it possible to pass a password in Maven Deploy in the ...
The settings.xml is considered personal, so for that reason the username+password are stored in the (user-) settings.xml .
Read more >
Dynamic username and password - Alteryx Community
Hi , I am developing a workflow in which I am getting data from external URL , i want users to get a...
Read more >
Credentials Processes in Windows Authentication
Passes the user's credentials through a secure channel to the domain controller and returns the domain security identifiers (SIDs) and user ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found