1

I am completely new to the protractor and currently, I'm testing my login page using my own login data and I want to use dummy data as profile login data. Can these enter in my spec.ts file or protractor.conf.js file?

This is my spec.ts file:

    it('Navigate to the dashboard', () => {
        page.getEmailLogin().sendKeys('[email protected]');
        page.getPasswordLogin().sendKeys('123456');
        page.getSubmitLogin().click();
    
        const EC = browser.ExpectedConditions;
        browser.wait(EC.urlContains('localhost:49152'), 10000);
        browser.wait(EC.urlIs('http://localhost:49152/'), 10000);
    });

I tried to add this data to params field but the login page requires valid data confirmed by the user.

4
  • To make sure I understand your question, are you asking in which file to put the login data? specs.ts or protractor.conf.js?
    – return
    Dec 18, 2018 at 9:23
  • Actually, I need to add a dummy user to project without using real login data to test the login page regardless the which local environment is used. Dec 18, 2018 at 10:06
  • is you just want to authenticate for valid or invalid login data or you want to get logged in with wrong details
    – Rao
    Dec 18, 2018 at 11:06
  • I want to use wrong user details (add a fake user in the system) to log for further use of e2e regardless the developer who uses it. Dec 18, 2018 at 11:34

2 Answers 2

1

Config file has a params option:

Based on https://github.com/angular/protractor/blob/5.4.1/lib/config.ts:

"The params object will be passed directly to the Protractor instance, and can be accessed from your test as browser.params. It is an arbitrary object and can contain anything you may need in your test. This can be changed via the command line as: --params.login.user "Joe" "

In config file you add your params. You can add multiple types of credentials depending on your needs:

params: {
login: {
  email: '[email protected]',
  password: '123456'
}

},

In specs file you call them:

it('Navigate to the dashboard', () => {
  page.getEmailLogin().sendKeys(browser.params.login.email);
  page.getPasswordLogin().sendKeys(browser.params.login.password);
  page.getSubmitLogin().click();
}
2
  • I tried and system displayed an error message stating that invalid email and password. I want the system to ignore it and log in. Is it possible? Dec 18, 2018 at 11:36
  • Why would you want to login with invalid credentials? It would be a huge security issue. Can't you create a test account?
    – return
    Dec 18, 2018 at 11:41
0

As a good practice keep your data separate in external json files and read into JS objects.

// Read json file into an data Object
var json = require('path/to/json/testData.json');

// Now you can access data from your json file as usual:
var users = json.users;   //Example 1
var data = json['data'];  //Example 2

Your Answer

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

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