I have added Assertion in my tc and make the login tc failed but I am not getting any output on console



  • I have added Assertion(Assert.asserttrue(true,"login failed")) in my every tc and conditions are according to that but when login tc failed I am not getting any output on console provided in assertion, that this tc is failed due to this this reason.

    Login page:

    public class LoginPage {
         private WebDriver driver;
    
        public LoginPage(WebDriver driver) throws Exception {
            PageFactory.initElements(driver, this);
            this.driver=driver;
        }
    
        @FindBy(how = How.ID, using = PageUtility.SIGNIN_USERNAME_ID)
        @CacheLookup
        public WebElement userNameTextField;
    
        @FindBy(how = How.ID, using = PageUtility.SIGNIN_PASSWORD_ID)
        @CacheLookup
        public WebElement passwordTextField;
    
        @FindBy(how = How.ID, using = PageUtility.SIGNIN_SUBMIT_ID)
        @CacheLookup
        public WebElement signInButton;
    
        public WebElement getUserNameTextField() {
            return userNameTextField;
        }
    
        public void setUserNameTextField(WebElement userNameTextField) {
            this.userNameTextField = userNameTextField;
        }
    
        public WebElement getPasswordTextField() {
            return passwordTextField;
        }
    
        public void setPasswordTextField(WebElement passwordTextField) {
            this.passwordTextField = passwordTextField;
        }
    
        public WebElement getSignInButton() {
            return signInButton;
        }
    
    
    }
    

    Login Business:

    public class LoginBusiness  {
    
        private WebDriver driver;
        LoginPage loginPage;
        public LoginBusiness(WebDriver driver) throws Exception {
            this.driver = driver;
            loginPage = new LoginPage(driver);
    
        }
    public void loginToApplication() throws Exception {
            loginPage.getUserNameTextField().clear();
            Properties properties = Utility.getproperties(Constant.CONFIGURATION_PROPERTIES_FILE_PATH);
            String username = properties.getProperty(Constant.USERNAME);
            loginPage.getUserNameTextField().sendKeys(username);
            String password = properties.getProperty(Constant.PASSWORD);
            loginPage.getPasswordTextField().clear();
        //  ScreenshotUtility.captureScreenShot(driver);
            loginPage.getPasswordTextField().sendKeys(password);
    
            loginPage.getSignInButton().click();
    
        }
    
    }
    

    Login test:

    public class LoginTest{
    
        WebDriver driver;
    
         @BeforeClass
         public void launchApplication() throws Exception
           {
              driver=Driver.getDriver();
            }
    
         @Test
         public void loginToGmsrApplication() throws Exception {
         LoginBusiness loginBusiness= new LoginBusiness(driver);
          loginBusiness.loginToApplication();
          Assert.assertTrue(true, "login unsuccessful.");
    
         }   
    
    }
    


      ##



    • AssertTrue(true, "message") is always going to be successful as you're asking it to assert that true is true!

      You need the first argument of assertTrue to be something that will fail if the login was not successful, e.g. the presence of an element located on the page that appears after a successful login, but not after a failed one.

      E.g.

      loginBusiness.loginToApplication();
      Assert.assertTrue(homePage.hasLoaded(), "login unsuccessful");
      

      with the hasLoaded method being something like

      public boolean hasLoaded() {
      
        try {
          driver.findElement(By.id("homePageElement");
        } catch(NoSuchElementException | TimeoutException e) {
          return false;
        }
      
        return true;
      
      }
      


    Suggested Topics

    • 2
    • 2
    • 2
    • 2
    • 2
    • 2
    • 2
    • 2