Validate Login

I wants to automate login page where I wants to validate it completely like when I enter blank input then it will generate error message which will be captured, duplicate entry will generate error, username enter but password text left blank then error message generated, invalid username and valid password generate error and like many more case. I have also used data driven method and using excel file for inputs. I have completed almost test cases but I wants to know how to validate it using trycatch method or using if else method. looking for help in urgently.

Thanks
Nazneen

hi nazneen,
all that you want to do in one script?

Andrej Podhajský said:

hi nazneen,
all that you want to do in one script?

yes

try

{

if (“Username”&& “Password” == ‘’)

{

WebUI.verifyElementPresent(findTestObject(‘Object Repository/Add Listing/Page_Workilo Welcome/BlankInput’), 5)

}

and now I am confuse how to do all the validation here using try catch or if else method

@andrej if we use selenium then all function take place in same test cases. that’s why I wants to write it in same test case.

mate, don’t do that … don’t go that road, it leads to maintenance madness and non-reusability hell.
if you need logical groups, use test suites, or group test cases (test case used only to call other test cases) but try to have TC with single purpose.
This does not mean that you cannot combine scripts (like if you want test forgott passw. you need to create user first and just after that test of password recovery) but keep purpose of TC as simple and as atomic as possible - this will also help you in reporting test results in much readable and clean way. better to have 10 tests with specific names describing real goal of that test than 1 misleading.

1 Like

as i’m reading your response i’m bit confused…

Andrej Podhajský said:

mate, don’t do that … don’t go that road, it leads to maintenance madness and non-reusability hell.
if you need logical groups, use test suites, or group test cases (test case used only to call other test cases) but try to have TC with single purpose.
This does not mean that you cannot combine scripts (like if you want test forgott passw. you need to create user first and just after that test of password recovery) but keep purpose of TC as simple and as atomic as possible - this will also help you in reporting test results in much readable and clean way. better to have 10 tests with specific names describing real goal of that test than 1 misleading.

Okay @andrej got your point but it leads to generate too many test cases and that’s why I wants to make it in single test case. though if I make 10 test cases then how can I grouping them. Would you like to make me single Test scenario for all this test cases?

you can call test cases one from another and even use parameters in calls
look here: https://docs.katalon.com/display/KD/Call+test+case

Andrej Podhajský said:

as i’m reading your response i’m bit confused…

Oh actually I wants to say like If I choose try catch method in this manner the code will be like :

try

{

if (“Username”&& “Password” == ’ ')

{

// then I wants to print the captured error message here

}

// next compare

else if (“Username” || “Password” == ’ ')

{

// then It prints another captured error message

}

and so on in this manner…

Can you get my point now?

Okay so here is my complete code:

for(def row=1; row<=findTestData(‘SystemLogin’).getRowNumbers();row++)

{

WebUI.openBrowser(’’)

WebUI.navigateToUrl(‘https://www.workilo.com/’)

WebUI.maximizeWindow()

WebUI.click(findTestObject(‘Object Repository/Add Listing/Page_Workilo Welcome/a_Log In’))

WebUI.setText(findTestObject(‘Object Repository/Add Listing/Page_Workilo Welcome/input_email_address’), findTestData(‘SystemLogin’).getValue(

    "Username", row), FailureHandling.STOP\_ON\_FAILURE)

WebUI.setText(findTestObject(‘Object Repository/Add Listing/Page_Workilo Welcome/input_password’), findTestData(‘SystemLogin’).getValue(

    "Password", row), FailureHandling.STOP\_ON\_FAILURE)

WebUI.click(findTestObject(‘Object Repository/Add Listing/Page_Workilo Welcome/input_button’))

}

So now if I call 2 or more test cases here then it will depend on user activity.So again I have to use try catch method. now suggest me what should my approach to overcome this situation?

@andrej Actually I am getting all the login credential from excel sheet and it contains all the valid and invalid input then how can I make separate test cases? please guide me.

i was thinking this would be the case… i suggest add 1 more column to excel - put some code there (up to you) and based on that code, you can decide in script what to do.
eg code LGOK - like login OK - use path for normal login
LGFP login forgot password
LGWP login wrong password
then you can use if-then-else if-else construct to manage correct usage of your data

Yes I have done in the same manner like in excel first row I have enter blank inputs. In 2nd row I have entered invalid email id then in 3rd row I have entered invalid password.
but now I got stuck how can I define or capture error message which is generated when I enter invalid login credential. can you please help me out?

@Marek Melocik had discussion about posting errors to log hope it help you

please im facing the same issue so could you help me i used excel data file too which contain valid and invalid email and password

Hi Asma,
I will suggest you from my personal experience that if you are beginner in coding then first learn selenium.Selenium have opensource and large platform to help beginners but if you start it with katalon then you need help in every steps. on the contrary, Selenium will also help you to learn katalon because We also use selenium code in katalon. but if you directly skip to katalon then sometime it will land you in great problem without any help support.

i really appreciate your advice but actually this is an urgent task i tried to do it this way can you check it for me
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject

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

WebUI.openBrowser(’’)

WebUI.navigateToUrl(‘https://staging.tajercom.com/’)

WebUI.click(findTestObject(‘Registration/Page_tajercom Tajercom/main_login_btn’))

WebUI.setText(findTestObject(‘Registration/Page_tajercom Tajercom/input_ _email’), email)

WebUI.waitForElementVisible(findTestObject(‘Registration/Page_tajercom Tajercom/input_ _password’), 4)

WebUI.setText(findTestObject(‘Registration/Page_tajercom Tajercom/input_ _password’), password)

WebUI.click(findTestObject(‘Registration/Page_tajercom Tajercom/sign in_ btn-yellow’))

if(email=="asmananah98@gmail.com" && password==“111111”)
{
WebUI.click(findTestObject(‘Registration/Page_tajercom Tajercom/close_wlc_pop up’))
KeywordLogger log = new KeywordLogger()

	log.logInfo('you succsessfully loged in')

}

else if (email=="asmananah98@mail.com" && password==“111111”)
{

WebUI.verifyElementPresent(findTestObject('Object Repository/Registration/Page_   tajercom/this info is wrong msg'), 3)
KeywordLogger log = new KeywordLogger()

	log.logInfo('wrong email')

}

else if (email=="asmananah98@gmail.com" && password==“1111111”)
{

WebUI.verifyElementPresent(findTestObject('Object Repository/Registration/Page_   tajercom/this info is wrong msg'), 3)
KeywordLogger log = new KeywordLogger()

	log.logInfo('wrong password')

}

else if (email=="asmananah98@mail.com" && password==“1111111”)
{

WebUI.verifyElementPresent(findTestObject('Object Repository/Registration/Page_   tajercom/this info is wrong msg'), 3)
KeywordLogger log = new KeywordLogger()

	log.logInfo('wrong password and email')

}

it ran successfully but the messages not printed in the log viewer