automated testing ngx-datatable using robotframework with selenium - 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'

Related

robot-framework error:Message: element not interactable: ElementNotInteractableException

I am a new in python. Trying to delete a row from a table automatically using robot-framework. Table contained 3 visible rows. Here is my code
*** Settings ***
#Test Teardown Close Browser
Library SeleniumLibrary
Library Stringpip
*** Variables ***
${Reps_Menu_Button} xpath=//div[#data-testid='carrier-reps-list']//div[#data-cellheader='Menu']/button
${reps_Delete_Button} xpath=//reach-portal[13]//div[.='Delete']
${Save_Carrier_Button} xpath=//button[.='Save Carrier']
${Success_Toast} xpath=//div[#class='Toastify__toast Toastify__toast--success']
*** Test Cases ***
#Delete Reps :
wait until element is visible ${reps_menu_button}
click element ${reps_menu_button}
click element ${reps_delete_button}
handle alert ACCEPT
click element ${save_carrier_button}
wait until element is not visible ${success_toast}
Please guide me here. Whether I am missing anything? or doing anything wrong? Thanks in advance :)
Check the variables you created. Variable names are case sensitive.

Robot Framework: Re Run Failed Test Cases

In Robot Automation, how to re-run the failed test case immediately if it is failed, before going to another test case execution.
For instance,
*** Test Cases ***
Login User And Create Another User
Login User ....
Create Another User ...
Login With New User
Login User..
Test Function ABC
.....
.....
Since one test has a dependency on another test, I need to re-run the failed case immediately after it is failed. Before executing another test.
In one word, you can't, and you shouldn't; a case is a case, with binary outcome. And if you have dependencies between tests, that's a smelly design; try to change it to a pre-condition (env setup) for the second case, so it is atomic.
Disclaimer: this rant is for the automatic re-execution in a single run. After a run has finished, RF has baked-in functionality to re-execute just the failed ones (so flaky tests are given the chance to succeed); but as I understood your question, you are not asking for the latter.
In two words, if you really need to do it, you can; extract the whole test case in a keyword, and call it inside Wait Until Keyword Succeeds, giving it 2 (or more?) attempts:
*** Test Cases ***
Test Function ABC
Wait Until Keyword Succeeds 2 times 100ms The Actual Test For Function ABC
*** Keywords ***
The Actual Test For Function ABC
.....
.....

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

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

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

Selenium SelectWindow Command not working

Selenium Select Window command fails and shows "Could not find window with title....". but if i Execute the Select Window command alone it passes the case and verifying the elements.
Code i used:
public void testDefaultlogo() throws Exception {
selenium.open("http://Sitename/samp.aspx");
selenium.type("ctl00_mainContentPlaceHolder_txt_LoginName", "uname");
selenium.type("ctl00_mainContentPlaceHolder_txt_Password", "pwd#12");
selenium.click("ctl00_mainContentPlaceHolder_btn_login");
selenium.waitForPageToLoad("60000");
selenium.click("ctl00_defaultLogo");
selenium.selectWindow("Sample~Window-ID");
verifyEquals("http://Sitename/index.html", selenium.getLocation());
selenium.close();
selenium.selectWindow ("null");
verifyTrue(selenium.isElementPresent("ctl00_defaultLogo"));
I mean by clicking one by one of the follwing commands in Selenium IDE it shows green but if i run the case it failed and shows as i mentioned above
What I can get from your code is that, clicking the "ctl00_defaultLogo" will popup another window. The possible issue could be that after write the command selenium.click("ctl00_defaultLogo") you need to wait for the popup to load.
The possible resolution, insert the command
selenium.WaitForPopUp("Sample~Window-ID", "5000");
before the
selenium.selectWindow("Sample~Window-ID");
This will cause selenium to wait for 5 secs before selecting the popup window.
Hope this helps!!!
some times it may not work for that u better use.
open_window("URL","WindowID or title or name");
selenium.selectWindow("WindowID or title or name");