I want to pass or fail the tests of “Login” function based on fields available on the second . I used “xpath” to capture the fields. But it does not capture the fields of the second . I suppose the reason is the second is not loaded when the code tries to check the fields of the second . Because when I tried to capture one of the fields of the Login , it does not show an error message.

login_page.ts
driver: any;

//Define Locators
_email_field = "user_email";
_password_field = "user_password";
_login_ ="commit"
_login_url: string = 'https://sso.teachable.com/secure/42299/users/sign_in?clean_login=true&reset_purchase_session=1';


constructor(){  
    this.driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.chrome()).build();

    this.driver.get(this._login_url).then(function (err:any) {
        console.log(`Page opened`);            
    })

}

enterEmail(email:any){
    this.driver.findElement(By.id(this._email_field)).sendKeys(email);        
}  

enterPassword(password:any){
    return this.driver.findElement(By.id(this._password_field)).sendKeys(password);
}

clickLoginButton(){
    return this.driver.findElement(By.name(this._login_)).();
}

public login(email:any, password:any) {

     return this.driver.getCurrentUrl().then(() =>{           

        this.enterEmail(email);
        this.enterPassword(password);
        this.clickLoginButton()

        console.log(`login  clicked`);  

    })

}public verifyLoginSuccessful()
{

    try{
        this.driver.findElement(By.xpath(".//*[@id='new_user']/div[1]/label")); //This field available on login page
        this.driver.findElement(By.xpath(".//*[@id='nav-bar']//span[text()='User Settings']"));           
        this.driver.findElement(By.xpath(".//*[@id='search-courses']"));
        console.log("Element Found");
    }
    catch(e){
        console.log("Element Not Found");
    }

login.test.ts

 it('Should log into kodeit' ,async()=>{
        await loginPage.login("[email protected]", "abcabc").then(()=> {
            console.log(`Return to test after logged in`);  
        }).then(()=> {
               let result = loginPage.verifyLoginSuccessful();
               expect(result).toBeTruthy();
    })   



Source link https://sqa.stackexchange.com/questions/34775/how-to--till-next-page--after-a-button-click-in--

LEAVE A REPLY

Please enter your comment!
Please enter your name here