How to verify Multiple lines at once in robot framework

Hi Team,

I need to verify two lines at once in robot framework, Can we please how to do it.

Ex: Log level is x
Process name is y.

I tried using Wait Until Page Contains keyword, but didnt work

Hi Madhurya,

Not sure I understand the need to verify both in a single keyword?

From Wait Until Page Contains i’m guessing you’re using SeleniumLibrary?

so why not just run the 2 tests sequentially something like:

Page Should Contain    Log level is x
Page Should Contain    Process name is y.
  • If the page doesn’t contain Log level is x, test fails at the first Page Should Contain.
  • If the page does contain Log level is x but not Process name is y, then test fails at the second Page Should Contain.
  • test will only pass if both items are present.

If you really need to test both with a single keyword I guess you could create a keyword for that, something like this:

*** Test Cases ***
My Example Test
    Go To    http://my.example/page
    Page Should Contain Both        Log level is x        Process name is y

*** Keywords ***
Page Should Contain Both
    [Arguments]    ${firstchk}    ${secondchk}
    Page Should Contain    ${firstchk}
    Page Should Contain    ${secondchk}

Dave.

Thank you for replying Dave.
My question is, is it possible anyway where we can verify both the lines at the same time, Because the page contains many lines with log level x, but the process name will be unique.
Ex:
Log Levels for process lrtd:
loglevel=DEBUG
Log Levels for process heap:
loglevel=DEBUG
Log Levels for process sip:
loglevel=DEBUG
I just want to verify the below line
Log Levels for process heap:
loglevel=DEBUG,
If I follow the above method, the test case will pass even if the log level is not DEBUG for heap

Hi Madhurya,

In that case I would suggest Page Should Contain Element combined with an xpath that checks both, as there is no simple way to check multiple conditions at once to that precision.

For this type of solution you’ll also need quite a complex xpath, so I’ll give an example, but if you need help, show the html of the page and I can help.

For this example HTML:

<div>
<span>Log Levels for process lrtd:</span>
<span>loglevel=DEBUG</span>
</div>
<div>
<span>Log Levels for process heap:</span>
<span>loglevel=DEBUG</span>
</div>
<div>
<span>Log Levels for process sip:</span>
<span>loglevel=DEBUG</span>
</div>

A simple xpath like //span[text()="Log Levels for process heap:"] will identify the span that first condition is in and //span[text()="loglevel=DEBUG"] will identify the span that the second condition is in individually, so what we nee to do is combine them and check that they both belong to the same parent element, a div in this example.

//div[ span[text()="Log Levels for process heap:"] and span[text()="loglevel=DEBUG"] ]

This xpath identifies a div that contains both span’s, so that:

Page Should Contain Element    //div[ span[text()="Log Levels for process heap:"] and span[text()="loglevel=DEBUG"] ]

This step will pass if both conditions are true, but fail if either one is not true as there will be not div that matches.

Unfortunately I don’t know of a simpler way, so I hope that helps,

Dave.

1 Like

Thanks Dave, I will try with the solution and check

The approach Damies13 provided with an conditional XPath is very much how I’d go about it.

Alternatively just for the sake of throwing an idea out there which builds onto Damies13 first solution , but if you wanted to create your own keyword to handle this, you can approach it by then adding the below within your keyword to handle it:

${IS_PRESENT_LOG_LEVEL} Run Keyword and Return Status ….

${IS_PRESENT_PROCESS_NAME} Run Keyword and Return Status ….

This would return true if it succeeds or false if it fails, so you’d put this before both page should contains…. lines you gave above, then just do a conditional check there after, if any are false then fail, if both are true return from keyword.

But I’d only do this, if this would be something you do more than once across tests, and if this was something you do more than once you could then pass arguments into the keyword for the process name/log level, and just build the argument variables into an XPath, other than that Damies13 conditional XPath is a simple clean solution.

2 Likes