mardi 14 mai 2019

How to stop tests in selenium using webdriver (JavaScript)?

I am running two tests using selenium webdriver in nodejs. I want first test to stop and then run the second one. But issues is that driver.close throws exception.

var webdriver = require('selenium-webdriver'),
    By = webdriver.By,
    until = webdriver.until;

var driver = new webdriver.Builder()
    .forBrowser('chrome')
    .build();

driver.get('https://www.website.com/');

var values = [{email:'correct@website.com',password:'correct'},{email:'wronguser@website.com',password:'wrong'}];


testCase(values[0].email,values[0].password);

// driver.close throws exception
driver.close();

testCase(values[1].email,values[1].password);

 function testCase(email,password){
  driver.wait(until.urlIs('https://dev.saayahealth.com/'))
  driver.findElement(By.id('inputEmail')).clear();
  driver.findElement(By.id('inputEmail')).sendKeys(email);
  driver.findElement(By.id('inputPassword')).clear();
  driver.findElement(By.id('inputPassword')).sendKeys(password);
  driver.findElement(By.tagName('button')).click().then(()=>{
    driver.wait(until.elementLocated(By.className('alert-danger'))).then(() =>{
      console.log('Failed login case - success');
    }).catch((e)=>{
      console.log(e);
    });
    driver.wait(until.urlIs('https://dev.saayahealth.com/home')).then(() => {
      console.log('Successful login case - success');
    }).catch((e)=>{
      console.log(e);
    });
  });

}

Error Message :

(node:1296) UnhandledPromiseRejectionWarning: NoSuchSessionError: invalid session id
  (Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Mac OS X 10.13.6 x86_64)

Expected Result should be :

- Successful login case - success
- Failed login case - success

Aucun commentaire:

Enregistrer un commentaire