How to overwrite the original keyword

29 views
Skip to first unread message

Ding

unread,
Feb 16, 2023, 10:07:29 AM2/16/23
to robotframework-users
Hello All~ I just have a question about using different keyword in different system.

For example, I need to use AppiumLibrary to create the test case for Android and iOS. All test cases are done for Android and I would like to reuse the test case for iOS.

In Android, it is fine to use the keyword - "Wait Until Element Is Visible" . But in iOS, i can only use "Wait Until Page Contains Element".

Since all test cases are written, and I dont want to have two set of test cases, would like to ask , 
1) is there a way to overwrite a keyword action to another keyword

or

2) how to edit the function or overwrite the function from the Library. (I tried to use  below monkey patching , but seems it is not useful. It still use the original code.)

edit_function.py:
from AppiumLibrary.keywords._waiting import _WaitingKeywords
def newFunction(self, locator, timeout=None, error=None):
   print("Hello")

def Replaceios():
   _WaitingKeywords.wait_until_element_is_visible =  newFunction


testcase.robot
*** Settings ***
Library AppiumLibrary
Library  edit_function.py

*** Test Cases ***
This is Test Case
   Replaceios
   Open Application   ${remoteUrl}.....
   Wait Until Element Is Visible        id=elementId
   


Craig Despeaux

unread,
Feb 16, 2023, 10:11:31 PM2/16/23
to robotframework-users
Have you considered using IF/ELSE statements to call the correct keyword depending on which device you're testing?

Craig

Ding

unread,
Feb 16, 2023, 10:48:51 PM2/16/23
to robotframework-users
Dear Craig

Thank you for the suggestion>~~<'

But I have used this keywords "Wait Until Element Is Visible" many times (> 100 times) in different test case. Therefore, it maybe difficult to write the IF/ELSE condition for 100 times. (If it is possible to write IF/ELSE condition once for each .robot file, then it is also okay)


For example:

testcase1.robot
*** Test Cases ***
This Is Test Case 1
   Wait Until Element Is Visible      xxx
   Go To Menu
   Wait Until Element Is Visible      XXX
   Execuite Transaction


testcase2.robot
*** Test Cases ***
This Is Test Case 2
   Wait Until Element Is Visible      xxx
   Go To Bottom
   Wait Until Element Is Visible      XXX
   Execuite Payment





Best Regards,
Ding



craiged...@gmail.com 在 2023年2月17日 星期五上午11:11:31 [UTC+8] 的信中寫道:

Craig Despeaux

unread,
Feb 16, 2023, 10:54:37 PM2/16/23
to hkbut...@gmail.com, robotframework-users
Write your own keyword replacing all the calls to Wait Until Element Is Visible and put the IF/ELSE logic once in your new keyword which calls Wait Until Element Is Visible or Wait Until Page Contains Element based on the device being tested.

Craig

Sent from my iPhone

On Feb 16, 2023, at 10:48 PM, Ding <hkbut...@gmail.com> wrote:

Dear Craig
--
You received this message because you are subscribed to a topic in the Google Groups "robotframework-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/robotframework-users/9ixgMAQQtLo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to robotframework-u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/robotframework-users/024c62aa-9252-4657-a3d3-795c17ef1243n%40googlegroups.com.

Ding

unread,
Feb 16, 2023, 11:13:19 PM2/16/23
to robotframework-users
ohhhhhhhhhhhhh, Yes , you are totally correct!!!!!!!!!!!

Why I made the case so complicated    🤣   

Thank you Craig and have a happy weekend <3

craiged...@gmail.com 在 2023年2月17日 星期五上午11:54:37 [UTC+8] 的信中寫道:
Reply all
Reply to author
Forward
0 new messages