Documentation

Looking for something in particular?

Authentication for Basic UI Login

This article provides instructions for Provar users to securely log in to applications using UI Connection. Provar provides the capability to login to any UI application using basic authentication. Users can effectively manage connections, test login flows, and ensure successful automation of test scenarios for any UI application.

Note: Authentication flow is maintained in the Auth handler page object file. 

Note:  The user must enter all of the information in the Auth Handler Page Object file. The login sequence and success condition must be maintained by the user in the same object file. 

Follow these steps to use Authentication for Basic UI login with Provar.

  1. Create an Auth Handler page object file.
  2. Create a UI Connection for basic authentication
  3. Enter all required details along with Auth Handler

  1. Do a Test Connection and click OK.

Users should be able to use this connection in the Test cases for both Test Authoring and Test Executions. The UI Connect step will handle the complete login process as defined in the UI Connection.

Sample JAVA file

package pageobjects.Sample;

import java.util.Map;

import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import com.provar.core.model.base.api.IRuntimeConfiguration;
import com.provar.core.testapi.ILoginPage;
import com.provar.core.testapi.ILoginResult;
import com.provar.core.testapi.annotations.Page;
import com.provar.core.testapi.java.UiLoginResultImpl;

@Page(title = "Basic_Login", connection = "Connection Name")
public class Basic_Login implements ILoginPage {

    @Override
    public ILoginResult doLogin(IRuntimeConfiguration runtimeConfiguration, WebDriver driver,
            Map<String, String> credentials) {

        // Connection 'Basic Username' and 'Basic Password' stored in userName and password
        // variables

        String userName = credentials.get(CREDENTIAL_USER);
        String password = credentials.get(CREDENTIAL_PASSWORD);

        // User can put wait here to load the page

        // Check if the user is already logged in
        if (isLoggedIn(driver)) {
            return new UiLoginResultImpl(true, driver);
        } else {
            // Enter user secret details to login and submit

            driver.findElement(By.xpath("<Xpath for username field>")).sendKeys(userName);
            driver.findElement(By.xpath("<Xpath for password field>")).sendKeys(password);

            driver.findElement(By.xpath("<Xpath for submit/login button>")).click();

            // User can put wait here to load the page (Added 2 second wait)
            waitForPageToLoad(2000);

            // Check again if user entered correct secret details
            boolean loginSuccess = isLoggedIn(driver);
            if (loginSuccess) {
                return new UiLoginResultImpl(true, "Login Successful.", driver);
            } else {
                return new UiLoginResultImpl(false, "Login failed : Please check your credentials.", driver);

            }
        }

    }

    private boolean isLoggedIn(WebDriver driver) {
        try {
            driver.findElement(By.xpath("<Xpath for field to check user is logged in>"));
        } catch (NoSuchElementException ex) {
            return false;
        }
        return true;
    }

    private static void waitForPageToLoad(long time) {
        try {
            Thread.sleep(time);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}

Feedback

Was this article helpful for you?
Documentation library

Trying to raise a case with our support team?

We use cookies to better understand how our website is used so we can tailor content for you. For more information about the different cookies we use please take a look at our Privacy Policy.

Scroll to Top