How to ignore Get Table Text from Cell, if xpath of cell not match - selenium

How to ignore Get Table Text from Cell, if xpath of cell not match? Becuase i want my test case still continues testing.
${tableFinal} Set Variable xpath=/html/body/div[2]/div[3]/div/form/table[3]
${totalPayAmount} Get Table Text from Cell ${tableFinal} 1 2

Using either Run Keyword And Continue On Failure or Run Keyword And Ignore Error can help with this. In the documentation the entire family of Run Keyword .... keywords.
The difference between the two is that one just returns the value, whereas the other also provides the status of the Keyword execution.
*** Test Cases ***
Test Case
${CoF_Pass_1} Run Keyword And Continue On Failure KW Pass
${CoF_Fail} Run Keyword And Continue On Failure KW Fail
${CoF_Pass_2} Run Keyword And Continue On Failure KW Pass
${IE_Pass_1} Run Keyword And Ignore Error KW Pass
${IE_Fail} Run Keyword And Ignore Error KW Fail
${IE_Pass_2} Run Keyword And Ignore Error KW Pass
*** Keywords ***
KW Pass
[Return] SomeRandomValue
KW Fail
Fail SomeFaileMessage
This then results into:
Starting test: Test Case
INFO : ${CoF_Pass_1} = SomeRandomValue
FAIL : SomeFaileMessage
INFO : ${CoF_Fail} = None
INFO : ${CoF_Pass_2} = SomeRandomValue
INFO : ${IE_Pass_1} = ('PASS', u'SomeRandomValue')
FAIL : SomeFaileMessage
INFO : ${IE_Fail} = ('FAIL', u'SomeFaileMessage')
INFO : ${IE_Pass_2} = ('PASS', u'SomeRandomValue')
Ending test: Test Case

Related

Robot Framework: Continue FOR loop if any keyword fails inside the loop

In the robot framework, I want to continue For Loop even if any keyword fails inside the Loop. For example, I have the code as shown below:
FOR ${member} IN #{all data members}
Keyword 1 ${member}
Keyword 2 ${member}
..............
Keyword n ${member}
END
If any keyword (e.g. Keyword 2) fails, the FOR loop execution should continue.
You could use keyword Run Keyword And Continue On Failure before each keyword or use keyword Run Keyword And Return Status and manually handle errors.

How to run if if else condition based on element visibility in selenium robot framework?

I am automating a user registration form flow, where successful registration shows a success message and any validation error throws alert text. For this, I am writing an if-else flow based on the visibility or presence of an element on the page. I will pass the control to a specific keyword with that condition
${SuccessBreadcrumb} is the element which is visible when the registration is successful
Code Snippet
*** Settings ***
Library SeleniumLibrary
*** Variables ***
${SuccessBreadcrumb} = xpath=//a[contains(text(),'Success')]
${SuccessMsgLocator} = xpath=//p[contains(text(), 'successfully created')]
${AlertMsg} = xpath=//div[#class='text-danger']
*** Keywords ***
Verify Validation Message
[Arguments] ${UserDetails}
sleep 2s
run keyword if ${SuccessBreadcrumb} is visible Keyword 1
# ... else Keyword 2
Keyword 1
[Arguments] ${UserDetails}
${AccountCreatedText} = get text ${SuccessMsgLocator}
should contain ${AccountCreatedText} ${UserDetails.ValidateMsg} ignore_case=true
# Keyword 2
Error Log
Run Keyword If ${SuccessBreadcrumb}, is visible, VerifySuccessText
Documentation:
Runs the given keyword with the given arguments, if condition is true.
Start / End / Elapsed: 20200213 12:27:52.882 / 20200213 12:27:52.882 / 00:00:00.000
12:27:52.882 FAIL Evaluating expression 'xpath=//a[contains(text(),'Success')]' failed: SyntaxError: invalid syntax (<string>, line 1)
In the documentation for Run Keyword If there does not exist an example with an object. However, using a combination of Run Keyword If with Run Keyword And Return Status will allow you to create a way to handle pass and fail situations within the same test case or keyword.
*** Settings ***
Library SeleniumLibrary
*** Test Cases ***
Check Element Visible
Open Browser
... url=https://www.google.com
... browser=chrome
${passed} Run Keyword And Return Status
... Element Should Be Visible xpath://*[#id="hplogo"]
Run Keyword If ${passed} Keyword Passed
... ELSE Keyword Failed
[Teardown] Close Browser
Check Element Not Visible
Open Browser
... url=https://www.google.com
... browser=chrome
${passed} Run Keyword And Return Status
... Element Should Be Visible xpath://*[#id="xxxx"]
Run Keyword If ${passed} Keyword Passed
... ELSE Keyword Failed
[Teardown] Close Browser
*** Keywords ***
Keyword Passed
Log To Console Passed
Keyword Failed
Log To Console Failed

automated testing ngx-datatable using robotframework with selenium

Has anyone used robotframework to test ngx-datatable? Since it isn't set up like a regular table, the selenium libraries Get Table Cell function doesn't work. Does anyone have an example of a work-around?
I've come up with a script that works for the time being.
*** Variables ***
${Table} = css=div[class^="datatable-row-center"]
*** Keywords ***
Get Value From Grid
#{RowNumber} 0 is the header
#{ColNumber} 0 is first column
[Arguments] ${RowNumber} ${ColNumber}
Sleep 3s
#{Table_Rows}= Get Webelements ${History_Table}
${Text}= Get Text #{Table_Rows}[${RowNumber}]
#{words} = Split String ${Text} \n
Log to Console #{words}[${ColNumber}]
[Return] #{words}[${ColNumber}]
This works as long as the class on the table rows remains 'datatable-row-center'

robot framework: exception handling

Is it possible to handle exceptions from the test case? I have 2 kinds of failure I want to track: a test failed to run, and a test ran but received the wrong output. If I need to raise an exception to fail my test, how can I distinguish between the two failure types? So say I have the following:
*** Test Cases ***
Case 1
Login 1.2.3.4 user pass
Check Log For this log line
If I can't log in, then the Login Keyword would raise an ExecutionError. If the log file doesn't exist, I would also get an ExecutionError. But if the log file does exist and the line isn't in the log, I should get an OutputError.
I may want to immediately fail the test on an ExecutionError, since it means my test did not run and there is some issue that needs to be fixed in the environment or with the test case. But on an OutputError, I may want to continue the test. It may only refer to a single piece of output and the test may be valuable to continue to check the rest of the output.
How can this be done?
Robot has several keywords for dealing with errors, such as Run keyword and ignore error which can be used to run another keyword that might fail. From the documentation:
This keyword returns two values, so that the first is either string
PASS or FAIL, depending on the status of the executed keyword. The
second value is either the return value of the keyword or the received
error message. See Run Keyword And Return Status If you are only
interested in the execution status.
That being said, it might be easier to write a python-based keyword which calls your Login keyword, since it will be easier to deal with multiple exceptions.
You can use something like this
${err_msg}= Run Keyword And Expect Error * <Your keyword>
Should Not Be Empty ${err_msg}
There are couple of different variations you could try like
Run Keyword And Continue On Failure, Run Keyword And Expect Error, Run Keyword And Ignore Error for the first statement above.
Option for the second statement above are Should Be Equal As Strings, Should Contain, Should Match.
You can explore more on Robot keywords

HP ALM OTA-API: How to update a test in testlab knowing the id?

I know the id of a test that is in a Testset and want to update your status, know how to do it using the API OTA?
Edit:
Thanks but current answer unfortunately doesn't work for me .
I put the example ( java) :
ITestSetFactory sTestFactory = (itdc.testSetFactory()).queryInterface(ITestSetFactory.class);
ITDFilter filterF=sTestFactory.filter().queryInterface(ITDFilter.class);
filterF.filter("TC_TEST_ID","531729");
System.out.println(filterF.newList().count());
The error:
Exception in thread "main" com4j.ComException: 800403ea (Unknown error) : Failed to Get Test Set Value : .\invoke.cpp:517
at com4j.Wrapper.invoke(Wrapper.java:166)
at com.sun.proxy.$Proxy13.newList(Unknown Source)
at TestQC.main(TestQC.java:64)
Any suggestions ?
The error occurs because you use the TestSetFactory instead of the TSTestFactory. You should use itdc.tsTestFactory() because it is TSTest objects you want to manipulate (aka test instances), not TestSet objects. The simplest way is to get the TSTestFactory of your TDConnection object, and use a filter to get the TSTest object and then set its status. Example code in Ruby:
ts_test_factory = tdc.TSTestFactory
filter = ts_test_factory.Filter
filter["TC_TEST_ID"] = "123" # test id from test plan
found_test_instances = filter.NewList
test_instance = found_test_instances.Item(1) # be careful if the test occurs in many test sets
test_instance.Status = "Passed"
test_instance.Post