Bin
Bin

Reputation: 49

How to not close the browser window in Protractor test?

Protractor automation test is trying to open an angular website and enter username and password. Issue is the browser window closes even before the site is completely loaded. I was able to verify the title of the website and when the elements are loading the browser window closes . But in the console it says username and password is entered. What is that I am missing to run the tests?

I tried: 1.Updating npm and windows-driver manager 2.Using Expected conditions and waiting until the login button is visible 3. Increasing wait time.

This is my config file:


  getPageTimeout: 60000,
  allScriptsTimeout: 60000,
  framework:'custom',
  frameworkPath: require.resolve('protractor-cucumber-framework'),

  params: {
    website: {
      websiteURL: 'XXXXX',
      wait: 10000,
      username: 'username',
      password: 'password',

    },

This is my step definition:


  await browser.get(browser.params.website.websiteURL)
  browser.sleep(8000)

});

When('I enter username and password and click on login button', async () => {
  await (launcherPageObject.username).isDisplayed
  launcherPageObject.username.click
  launcherPageObject.username.sendKeys(browser.params.launcher.username)
  console.log("Username is entered")
  await (launcherPageObject.password).isDisplayed
  launcherPageObject.password.click
  launcherPageObject.password.sendKeys(browser.params.launcher.password)
  console.log("Password is entered")
  await(launcherPageObject.submitButton).isDisplayed
  launcherPageObject.submitButton.click
 });```

This is the console log:

DevTools listening on ws://127.0.0.1:57287/devtools/browser/28ca8fcd-1028-4539-8332-c7663d2dfd14
.Username is entered
Password is entered


Thanks

Upvotes: 0

Views: 458

Answers (1)

Sergey Pleshakov
Sergey Pleshakov

Reputation: 8948

you are missing js code.. first of all parenthesis for methods, and then you don't resolve promises with await keyword

 await browser.get(browser.params.website.websiteURL)
 await browser.sleep(8000) // <---------------

});

When('I enter username and password and click on login button', async () => {
  await (launcherPageObject.username).isDisplayed();  // <---------------
  await launcherPageObject.username.click();  // <---------------
  await launcherPageObject.username.sendKeys(browser.params.launcher.username)
  console.log("Username is entered")

etc

Upvotes: 1

Related Questions