Marked Expected Fail as Passed Test Case

I got error in log like this

I think, I know the problem Dave. It’s not created dictionary when I define it in variables, and instead count the Create Dictionary as just another value.

Regards,

Ahmad

Hi Ahmad,

I thing you figured it out already, but these are backwards

you need to create a variable (string, list, dictionary, etc) before you can use it

${item}=    Create Dictionary    key=xx    value_text=xx    value=xx
${body}=    Create List    ${item}
${parameters}=    Create Dictionary    body=${body}
${data}=    Create Dictionary    to_number=xxx    to_name=xxx    category=xxx    language=xx    parameters=${parameters}

Also for future reference use 3 ` in a row to start/end a code block so your robot scripts don’t get messed up in the forum posts (this works in Github and some other forums too)

    ${var}=    Your keyword    Arg 1    Arg 2

Dave.

Hi Dave,

Yep-yep I figured it out already. turn out we can use [&] symbol to define it as dictionary and [@] as list. Still don’t know why I can’t use like below for save variables in variables maybe that kind of defining way is deprecated already.

${item}= Create Dictionary key=xx value_text=xx value=xx
${body}= Create List ${item}
${parameters}= Create Dictionary body=${body}
${data}= Create Dictionary to_number=xxx to_name=xxx category=xxx language=xx parameters=${parameters}

but thanks man, I think I start to get hang of it.

Regards,

Ahmad

1 Like

Hi Ahmad,

Yeah the use of [&] and [@] symbols, when and where had me a little confused as well, I wish it was better documented.

The syntax in the variables section is a little different because you can’t run keywords in there, the variables created there are basically static, but you can overwrite them from the command line.

here’s an example:

*** Variables ***
&{item}=    key=xx    value_text=xx    value=xx
@{body}=    ${item}
&{parameters}=    body=${body}
&{data}=    to_number=xxx    to_name=xxx    category=xxx    language=xx    parameters=${parameters}

*** Test Cases ***
Ahmad Variables
	Log		${item}
	Log		${body}
	Log		${parameters}
	Log		${data}

It seems you are, you’ll be helping others in this forum in no time :crossed_fingers:

Dave.

1 Like

Hello again Dave,

May I ask for suggestion. So I have test case to insert some value but it’s will be valid only 1 times. and then we will get message that value is existing for the second time we hit the endpoint.

Do you think we can use IF to assert that value is existing means it’s still passed. Thanks.

Regards,

Ahmad

Hi Ahmad,

Sure you can do that, just don’t assert the value, cause that will fail, but if an assert is the only way you can find out if the record is already created, wrap the assert in Run Keyword And Return Status and that will giver a True or False value you can use in you IF statement.

  • enter value and click create
  • check for the record exists message
    • if the first step is a GUI app you do something like get text
    • if the first step is a requests post, check the JSON response
  • IF “record exists message”
  • ELSE
    • call the rest of the keywords to finish creating the record
  • END

Dave.

Hi Dave,

Can you give me some code example that represent step you mention above(?) I still quite confused about that. Big Thanks in advance.

Regards,

Ahmad

Hi Ahmad,

Sure, here you go:

1st time you run it may create the employee record in the first test, if that happens (you’ll see it enter a DOB) run it again, then you can note the differences between what was skipped in each test to understand the difference between Pass Execution and Return From Keyword

Dave.

orangehrm.robot

*** Settings ***
Library 	Browser


Test Teardown		Close Browser		ALL

*** Variables ***
${Site}			https://opensource-demo.orangehrmlive.com/
${User}			Admin
${Pass}			admin123


*** Test Cases ***
Orangehrm Pass And End If Exists
	Orangehrm Login

	Orangehrm PIM

	Orangehrm Create Employee Pass		Person		Demo		1313

	Orangehrm Leave

	Sleep		10


Orangehrm Pass And Continue If Exists
	Orangehrm Login

	Orangehrm PIM

	Orangehrm Create Employee Return		Person		Demo		1313

	Orangehrm Leave

	Sleep		10



*** Keywords ***

Orangehrm Login
	New Browser		chromium		False
	${old_timeout} =    Set Browser Timeout    5 m
	New Page		${Site}
	Wait For Elements State		//input[@name="username"]		visible
	Fill Text		//input[@name="username"]		${User}
	Fill Text		//input[@name="password"]		${Pass}
	Click				//button[@type="submit"]
	Wait For Elements State		//*[text()="PIM"]		visible


Orangehrm PIM
	Click		//a/span[text()="PIM"]
	Wait For Elements State		button > i.bi-plus		visible

Orangehrm Leave
	Click		//a/span[text()="Leave"]
	Wait For Elements State		button[type="submit"]		visible

Orangehrm Create Employee Pass
	[Arguments]		${Surname}		${Given1}		${IdNumber}
	Click 	button > i.bi-plus
	Wait For Elements State		input.orangehrm-lastname		visible
	Fill Text		input.orangehrm-lastname		${Surname}
	Fill Text		input.orangehrm-firstname		${Given1}
	Fill Text		//label[text()="Employee Id"]/../..//input		${IdNumber}

	Click 	button[type="submit"]

	# //label[text()="Employee Id"]/../..//span
	# span.oxd-input-field-error-message
	${exists}= 	Run Keyword And Return Status 	Wait For Elements State		//label[text()="Employee Id"]/../..//span		visible		10
	IF		${exists}
		${msg}=    Get Text    //label[text()="Employee Id"]/../..//span
		IF		"${msg}" == "Employee Id already exists"
			Pass Execution				${msg}
		ELSE
			Fail		${msg}
		END
	END

	Log 	Fill in rest of the User Details

	Fill Text		//label[text()="Date of Birth"]/../..//input		1999-06-06
	Click 	button[type="submit"]

	Click		//a/span[text()="PIM"]


Orangehrm Create Employee Return
	[Arguments]		${Surname}		${Given1}		${IdNumber}
	Click 	button > i.bi-plus
	Wait For Elements State		input.orangehrm-lastname		visible
	Fill Text		input.orangehrm-lastname		${Surname}
	Fill Text		input.orangehrm-firstname		${Given1}
	Fill Text		//label[text()="Employee Id"]/../..//input		${IdNumber}

	Click 	button[type="submit"]

	# //label[text()="Employee Id"]/../..//span
	# span.oxd-input-field-error-message
	${exists}= 	Run Keyword And Return Status 	Wait For Elements State		//label[text()="Employee Id"]/../..//span		visible		10
	IF		${exists}
		${msg}=    Get Text    //label[text()="Employee Id"]/../..//span
		IF		"${msg}" == "Employee Id already exists"
			Return From Keyword		${msg}
		ELSE
			Fail		${msg}
		END
	END

	Log 	Fill in rest of the User Details

	Fill Text		//label[text()="Date of Birth"]/../..//input		1999-06-06
	Click 	button[type="submit"]

	Click		//a/span[text()="PIM"]

Hi Dave, I’m back with some question.

I want to ask what function we used when we want to check some variable I use is exist in certain file, and if it exist then expected status will set differently than current condition. Thanks.

Regards,

Ahmad

Hi Ahmad,

It depends on what sort of file it is, different types of files will need different strategies.

If it’s a simple text file you can use Get File from OperatingSystem Library to get the content of the file to a variable, then you can simply use BuiltIn’s Should/Should Not keywords (Should Contain, Should Be Equal As Strings, Should Not Contain, Should Not Match, etc)

Basically, once you get the value from whatever file type you have, into a variable it’s then easy to do a comparison with the BuiltIn keywords.

Dave.