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?

And this is my spec.ts file:

it('Navigate to the dashboard', () => {
    page.getEmailLogin().sendKeys('first@gmail.com');
    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);
});

And also i tried to add these data to params field but still login page require valid data confirmed by the user.

  • 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 '18 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. – Sanjani Gunathilaka Dec 18 '18 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 '18 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. – Sanjani Gunathilaka Dec 18 '18 at 11:34
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: 'first@gmail.com',
  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();
}
  • 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? – Sanjani Gunathilaka Dec 18 '18 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 '18 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, privacy policy and cookie policy

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