How to set username and password login so that no need re-login every testing

Hello,

How to set username and password login so that no need re-login every testing ? because when im testing web using katalon always from start and must login first? how to set username and password so that when testing a web no need to login (password and username already saved) ?
thank you

log in as a simple case and others case without login, then call the login case if needed. And use test suites to structure your flow.

this is not a good practice, what if you have thousands of tests and logging in takes let’s say 3 seconds, your tests have to deal with additional 3000 seconds just to run the login

Let me explain my idea by example.

Starting point

Katalon provides a sample Web UI project “healthcare”

This project bundles a sample Test Case named Main Test Cases/TC2_Verify Successful appointment. The source code is as follows:

import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject

import com.kms.katalon.core.model.FailureHandling
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

import internal.GlobalVariable

WebUI.comment('Story: Book an appointment')

WebUI.comment('Given that the user has logged into their account')

WebUI.openBrowser(GlobalVariable.G_SiteURL)

WebUI.callTestCase(findTestCase('Common Test Cases/Login'), [('Username') : 'John Doe', ('Password') : 'ThisIsNotAPassword'], 
    FailureHandling.STOP_ON_FAILURE)

WebUI.comment('And Appointment page is displayed')

if (true) {
    WebUI.selectOptionByLabel(findTestObject('Page_CuraAppointment/lst_Facility'), 'Hongkong CURA Healthcare Center', false)

    WebUI.check(findTestObject('Page_CuraAppointment/chk_Medicaid'))

    WebUI.check(findTestObject('Page_CuraAppointment/chk_Readmission'))

    WebUI.setText(findTestObject('Page_CuraAppointment/txt_VisitDate'), '27/12/2016')

    WebUI.setText(findTestObject('Page_CuraAppointment/txt_Comment'), 'Please make appointment as soon as possible.')
}

WebUI.comment('When he fills in valid information in Appointment page')

WebUI.click(findTestObject('Page_CuraAppointment/btn_BookAppointment'))

WebUI.verifyTextPresent('Appointment Confirmation', false)

WebUI.comment('Then he should be able to book a new appointment')

if (true) {
    WebUI.verifyMatch('Hongkong CURA Healthcare Center', WebUI.getText(findTestObject('Page_AppointmentConfirmation/lbl_Facility')), 
        false)

    WebUI.verifyMatch('Yes', WebUI.getText(findTestObject('Page_AppointmentConfirmation/lbl_HospitalReadmission')), false)

    WebUI.verifyMatch('Medicaid', WebUI.getText(findTestObject('Page_AppointmentConfirmation/lbl_Program')), false)

    WebUI.verifyMatch('27/12/2016', WebUI.getText(findTestObject('Page_AppointmentConfirmation/lbl_VisitDate')), false)

    WebUI.verifyMatch('Please make appointment as soon as possible.', WebUI.getText(findTestObject('Page_AppointmentConfirmation/lbl_Comment')), 
        false)
}

WebUI.takeScreenshot()
WebUI.closeBrowser()

A brain storming

I can split this single script into 5 Test Case scripts.

stepwised/TC2_00_openBrowser

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

import internal.GlobalVariable

WebUI.comment('Story: Book an appointment')

WebUI.comment('Given that the user has logged into their account')

WebUI.openBrowser(GlobalVariable.G_SiteURL)

stepwised/TC2_01_login

import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase

import com.kms.katalon.core.model.FailureHandling
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

WebUI.callTestCase(findTestCase('Common Test Cases/Login'), [('Username') : 'John Doe', ('Password') : 'ThisIsNotAPassword'],
	FailureHandling.STOP_ON_FAILURE)

WebUI.comment('And Appointment page is displayed')

stepwised/TC2_10_makeAppointment

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

if (true) {
	WebUI.selectOptionByLabel(findTestObject('Page_CuraAppointment/lst_Facility'), 'Hongkong CURA Healthcare Center', false)

	WebUI.check(findTestObject('Page_CuraAppointment/chk_Medicaid'))

	WebUI.check(findTestObject('Page_CuraAppointment/chk_Readmission'))

	WebUI.setText(findTestObject('Page_CuraAppointment/txt_VisitDate'), '27/12/2016')

	WebUI.setText(findTestObject('Page_CuraAppointment/txt_Comment'), 'Please make appointment as soon as possible.')
}

WebUI.comment('When he fills in valid information in Appointment page')

WebUI.click(findTestObject('Page_CuraAppointment/btn_BookAppointment'))

WebUI.verifyTextPresent('Appointment Confirmation', false)

WebUI.comment('Then he should be able to book a new appointment')

stepwised/TC2_20_verifyAppointment

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

if (true) {
	WebUI.verifyMatch('Hongkong CURA Healthcare Center', WebUI.getText(findTestObject('Page_AppointmentConfirmation/lbl_Facility')),
		false)

	WebUI.verifyMatch('Yes', WebUI.getText(findTestObject('Page_AppointmentConfirmation/lbl_HospitalReadmission')), false)

	WebUI.verifyMatch('Medicaid', WebUI.getText(findTestObject('Page_AppointmentConfirmation/lbl_Program')), false)

	WebUI.verifyMatch('27/12/2016', WebUI.getText(findTestObject('Page_AppointmentConfirmation/lbl_VisitDate')), false)

	WebUI.verifyMatch('Please make appointment as soon as possible.', WebUI.getText(findTestObject('Page_AppointmentConfirmation/lbl_Comment')),
		false)
}

WebUI.takeScreenshot()

stepwised/TC2_99_closeBrowser

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

WebUI.closeBrowser()

And finally, I will create a new Test Suite named stepwised, which binds the 5 Test Case scripts.

Now I can run the Test Suite stepwised. It runs just the same as the original Main Test Cases/TC2_Verify Successful appointment. No difference.

My idea

Please find that the Test Suite stepwised opens a single instance of web browser and reuse it for all component Test Case scripts. The Test Suite executes the login processing only once. And the “logged-in” status is retained for all the following Test Cases. The stepwised/TC2_10_makeAppointment and stepwised/TC2_20_verifyAppointment don’t repeat the login processing.

Imagine, you want to add more Test Case scripts into the Test Suite stepwised. Of course, you can do it. Additional Test Case scripts can reuse the browser instance. These scrits do not have to repeat the Login processing. They can do anything with the “already-logged-in” status retained.

Discussion

Not necessarily so. It depends how you design your test scripts.

Just for your information, please have a look at my previous post:

Let me assume, I opened Chrome with a Profile ‘Katalon user’ and logged-in Salesforce applition. If I could somehow let Katalon Studio to start Chrome with the same Profile ‘Katalon user’, then the test will run without requiring manual intervention. But how can I achieve it?

I am not sure if my previous article is relevant to those who were concerned with this topic.