LambdaTest Community

Find answers, support, and inspiration from other users

Questions
LambdaTest Community
Unanswered

keep session after login - selenium - javascript

I am trying to automate couple of pages using selenium web driver and node js . I was able to login , but after login I want to use same session initiated by web driver so that I can do automated testing on session protected page. This is my attempt

async function login(){
    Let  d =  await new Builder()
                        .forBrowser('chrome')
                        .build();
    await d.get('https://demo.textdomain.com/')
    await d.findElement(By.id('username')).sendKeys('admin ')
    await d.findElement(By.id('password')).sendKeys('admin');
    await d.findElement(By.css('button[type="submit"]')).click();
    await d.getPageSource().then(function(content) {

            if(content.indexOf('Welcome text') !==-1 ) {
             console.log('Test passed');
             console.log('landing page');
             d.get('https://demo.textdomain.com/landingpage') //this is still going to login page as i cannot use the previous session 
            } else {
                console.log('Test failed');
                return false;
            }
            //driver.quit();
        });

}

login();

Am I accidentally discarding the browser after login.

Up Vote Down Vote 0 Votes
Posted 29 days ago

Answers