# Marked Expected Fail as Passed Test Case

**URL:** <https://forum.robotframework.org/t/marked-expected-fail-as-passed-test-case/5379>\
**Category:** Robot Framework\
**Created:** [2 March 2023 08:10 UTC](https://forum.robotframework.org/t/marked-expected-fail-as-passed-test-case/5379 "2023-03-02T08:10:10Z")\
**Posts on this page:** 11\
**Page:** 2

<div class="post-metadata">

**Author:** ![afadhlir](https://avatars.discourse-cdn.com/v4/letter/a/e56c9b/32.png) [@afadhlir](https://forum.robotframework.org/u/afadhlir)\
**Post date:** [6 March 2023 07:18 UTC](https://forum.robotframework.org/t/marked-expected-fail-as-passed-test-case/5379/22 "2023-03-06T07:18:52Z")

</div>

I got error in log like this

 ![error](https://europe1.discourse-cdn.com/flex005/uploads/robotframework1/original/2X/2/2452d43eb52d52e6c225fa816ff32e55b0126dbc.png)

---

<div class="post-metadata">

**Author:** ![afadhlir](https://avatars.discourse-cdn.com/v4/letter/a/e56c9b/32.png) [@afadhlir](https://forum.robotframework.org/u/afadhlir)\
**Post date:** [6 March 2023 07:28 UTC](https://forum.robotframework.org/t/marked-expected-fail-as-passed-test-case/5379/23 "2023-03-06T07:28:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [6 March 2023 09:02 UTC](https://forum.robotframework.org/t/marked-expected-fail-as-passed-test-case/5379/24 "2023-03-06T09:02:24Z")

</div>

Hi Ahmad,

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

> [@afadhlir](#):
>
> ${data}= Create Dictionary to\_number=xxx to\_name=xxx category=xxx language=xx parameters=${parameters}  
> ${parameters}= Create Dictionary body=${body}  
> ${body}= Create List ${item}  
> ${item}= Create Dictionary key=xx value\_text=xx value=xx

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

```python
${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)

```python
    ${var}= Your keyword Arg 1 Arg 2

```

Dave.

---

<div class="post-metadata">

**Author:** ![afadhlir](https://avatars.discourse-cdn.com/v4/letter/a/e56c9b/32.png) [@afadhlir](https://forum.robotframework.org/u/afadhlir)\
**Post date:** [6 March 2023 10:00 UTC](https://forum.robotframework.org/t/marked-expected-fail-as-passed-test-case/5379/25 "2023-03-06T10:00:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [6 March 2023 10:20 UTC](https://forum.robotframework.org/t/marked-expected-fail-as-passed-test-case/5379/26 "2023-03-06T10:20:54Z")

</div>

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:

```python
***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}

```

> [@afadhlir](#):
>
> I think I start to get hang of it.

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

Dave.

---

<div class="post-metadata">

**Author:** ![afadhlir](https://avatars.discourse-cdn.com/v4/letter/a/e56c9b/32.png) [@afadhlir](https://forum.robotframework.org/u/afadhlir)\
**Post date:** [8 March 2023 02:50 UTC](https://forum.robotframework.org/t/marked-expected-fail-as-passed-test-case/5379/27 "2023-03-08T02:50:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [8 March 2023 07:02 UTC](https://forum.robotframework.org/t/marked-expected-fail-as-passed-test-case/5379/28 "2023-03-08T07:02:16Z")

</div>

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](https://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Run%20Keyword%20And%20Return%20Status) 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”
  - call something like [Pass Execution](https://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Pass%20Execution) or [Return From Keyword](https://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Return%20From%20Keyword)

- ELSE
  - call the rest of the keywords to finish creating the record

- END

Dave.

---

<div class="post-metadata">

**Author:** ![afadhlir](https://avatars.discourse-cdn.com/v4/letter/a/e56c9b/32.png) [@afadhlir](https://forum.robotframework.org/u/afadhlir)\
**Post date:** [9 March 2023 02:27 UTC](https://forum.robotframework.org/t/marked-expected-fail-as-passed-test-case/5379/29 "2023-03-09T02:27:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [9 March 2023 08:41 UTC](https://forum.robotframework.org/t/marked-expected-fail-as-passed-test-case/5379/30 "2023-03-09T08:41:10Z")

</div>

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](https://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Pass%20Execution) and [Return From Keyword](https://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Return%20From%20Keyword)

Dave.

_orangehrm.robot_

```python
***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"]

```

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/robotframework1/original/2X/5/59d4f327b306bcc3cff841466ab226a395642db9.png)

---

<div class="post-metadata">

**Author:** ![afadhlir](https://avatars.discourse-cdn.com/v4/letter/a/e56c9b/32.png) [@afadhlir](https://forum.robotframework.org/u/afadhlir)\
**Post date:** [17 March 2023 04:04 UTC](https://forum.robotframework.org/t/marked-expected-fail-as-passed-test-case/5379/31 "2023-03-17T04:04:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [17 March 2023 04:37 UTC](https://forum.robotframework.org/t/marked-expected-fail-as-passed-test-case/5379/32 "2023-03-17T04:37:38Z")

</div>

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](https://robotframework.org/robotframework/latest/libraries/OperatingSystem.html#Get%20File) 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](https://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Should%20Contain), [Should Be Equal As Strings](https://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Should%20Be%20Equal%20As%20Strings), [Should Not Contain](https://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Should%20Not%20Contain), [Should Not Match](https://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Should%20Not%20Match), 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.

[Previous page](https://forum.robotframework.org/t/marked-expected-fail-as-passed-test-case/5379.md?page=1)
