I am looking to see if this is possible... I am writing UI tests for web and mobile in Cucumber (using Protractor for web and Appium for mobile) and would like to store login details (email and password) in a text file (or another type of file). Is there anyway to run a Feature/Steps file to include a text file so the information stored within the file will be used when logging in to our web/mobile app? Not stored directly inside the Steps file for example.

This was a question that came up during a recent meeting and I couldn't find an answer, so maybe someone else has come across this before?

If it's possible an explanation would be great!

4 Answers 4


One way is to store these User/Pass in application property files. I am using Spring though you can check this link to see how you can read the application property.

In this way, you can have and save multiple username and password for different staging environments in an external file.

For example your property file (release.properties) contains:

    mainpage.loginEmail1 = [email protected]
    mainpage.pass1 = 1234
    mainpage.loginEmail2 = [email protected]
    mainpage.pass2 = 6666

Then in your Cucumber scenario (.feature) you have:

Given I am logged in with user no "2"

And in your step implementation:

private String loginEmail1;
private String loginEmail2;

@When("^I am logged in with user no no \"([^\"]*)\"$")
    public void logInWithUser(final String userNo) {
            switch (userNo) {

            case "1" :
                userName = loginEmail1;

            case "2" :
                userName = loginEmail2;
pageUIAuthPage.loginAs(userName, yourPass);

Sure, you can store credentials or other useful data in a text file. Here's an example from a StackOverflow question where someone is using a YAML file to store credentials, which they then load in env.rb:



You can store the credentials in yaml files, and then load the yaml files in the test steps or add the credentials to your global context. (ie. Given a user)

I would recommend keeping the files separate, one for mobile and one for web app.

For the web app I am guessing you are using javascript since you mentioned protractor. You can look at something like jsyaml to load yaml into json.

For appium you can look at the yaml gem for ruby. I have not done yaml loading on java so I do not have recommendation there.


For Protractor/JavaScript , use JSON for data driven testing.

JSON example:

    {"username":"User1", "password":"Password1"}, 
    {"username":"User2", "password":"Password2"}, 
    {"username":"User3", "password":"Password3"}

You may store data in a json file and simply read into a variable and use it as required:

var testData = require('../example/Test Data/Test.json');
    describe('LoginPage', function() {
    it("data.description", function () {

By using JSON , you may define complex data hierarchy upto Nth level deeply nested if required.

Complex data definition example using Json:

  "squadName": "Super hero squad",
  "homeTown": "Metro City",
  "formed": 2016,
  "secretBase": "Super tower",
  "active": true,
  "members": [
      "name": "Molecule Man",
      "age": 29,
      "secretIdentity": "Dan Jukes",
      "powers": [
        "Radiation resistance",
        "Turning tiny",
        "Radiation blast"
      "name": "Madame Uppercut",
      "age": 39,
      "secretIdentity": "Jane Wilson",
      "powers": [
        "Million tonne punch",
        "Damage resistance",
        "Superhuman reflexes"
      "name": "Eternal Flame",
      "age": 1000000,
      "secretIdentity": "Unknown",
      "powers": [
        "Heat Immunity",
        "Interdimensional travel"

If we loaded this object into a JavaScript program, parsed in a variable called superHeroes for example, we could then access the data inside it using the dot/bracket notation as below:


To access data further down the hierarchy, you simply have to chain the required property names and array indexes together. For example, to access the third superpower of the second hero listed in the member's list, you'd do this:


Alternatively for more flexible & complex data definitions, one may store data as JS objects in which is a bit more flexible compared to JSON files.

JS Object Example:

var person = {

Source: https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/JSON https://www.w3schools.com/js/js_json.asp

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.