How to list all keywords accessible at given time?

563 views
Skip to first unread message

alans09

unread,
Jul 25, 2021, 10:10:17 AM7/25/21
to robotframework-users
Hi all, 

 i'm looking for a feature/code that will show mi list of all keywords, that are currently available for user.

For exemple:
 you can access all keywords, that are in BuiltIn() library. I want a way to simple show list of all keywords and log it into console in a runtime.

something like:

Log    get_all_available_keywords    WARN

result should be something like  # ['log', 'run keywords', 'run keyword', 'fail', ...] 

Is this possible to get?  

Thanks

Vikas Kumar

unread,
Jul 27, 2021, 4:48:23 AM7/27/21
to ala...@gmail.com, robotframework-users
- In the robot framework the keywords are of two types 
   - Library imported in the current file and all resources and Library references in backward imports in all files.
   - Some keywords defined in the current file or namespace.

So these all keywords should be in the available at that namespace or module or file you are on.

How to print them, not sure what is the use case but ${KEYWORD STATUS} is there for last status of keyword.

you can use python library to print object details :  dir() this method can give details.


--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/robotframework-users/dc2793b3-aac8-4f15-a342-cfb6ebdae3b1n%40googlegroups.com.

Tatu Aalto

unread,
Jul 27, 2021, 5:17:25 AM7/27/21
to Tomas Pekarovic, robotframework-users
Hi

Interesting idea, but it looks like you are looking a solution to a problem. And for you, listing keywords looks like solution. But perhaps we could help you better, if you explain why you want to list the keywords?

-Tatu
Send from my mobile

--

Tomas Pekarovic

unread,
Jul 27, 2021, 8:51:45 AM7/27/21
to Tatu Aalto, robotframework-users
Hi Tatu...

I have a library that is built as   PageObject   ....   
There are some objects that are imported at runtime... so at the start library does not have all the information about keyword available at a given time.


Keyword  Current Page Should Be    Page1   is doing     builtin.import_library(Page1)  

This library have set of keyword associated with it... also this keyword is doing something like this:

old_order = self.builtin.set_library_search_order()
new_order = (str(page),) + old_order
self.builtin.set_library_search_order(*new_order)

So at the end, you have all keywords from all pages available  (this is still in progress as I'm still working on it.. It is possible that at the end there will be always only actual PageObject available)


This keyword library provides keywords for standard   manual testers.     I have all the library keywords described, but for manual testers it is not always easy to write some tests, and if they want to edit some step, they need (because of their nature) to run a full test from the start to the end after every change.

Even if they try to use keywords and write tests, it always ends up that they will mess up tests. 

I found out that it is much better, if they can 'run keywords' at runtime.. so I started to play with something like this
(also for automation engineers it is easier to debug keywords as they write it because the app under test is a big financial application and if you need to debug something at the end you have to run a lot of steps before it. ):

def run_debug_keyword(self):
kw = None
while kw != "END":
kw = get_value_from_user("INPUT KEYWORD")
args = get_value_from_user("INPUT ARGUMENTS SEPARATED BY 4 SPACES").strip()
if not args:
self.builtin.run_keyword(kw.strip())
else:
args = args.split(" ")
self.builtin.run_keyword(kw, *args)
So they can start a test case  (let test do setup for them, and start browser with specific url)  and afterwards they are able to navigate to the required part of the application and run keywords at runtime just by adding the keyword they want to run to 'dialogs'.


And this is the reason I'm looking for a way to give them a select with all the available keywords right at a runtime so they only select one of them and write down arguments.

It will be great if you can not only get keywords, but maybe also docstring from them to display it. 

Maybe there is another way, how to do this... to  run keywords 'live' while the test is running? Just break execution and wait for  'keyword' inputs?


At the end the idea behind this is to 'save' locally all the keywords they are using (if there is no error) and let them 'record' test case 'manually' 


I hope this makes sense. 

Tomas

Tatu Aalto

unread,
Jul 27, 2021, 9:08:27 AM7/27/21
to Tomas Pekarovic, robotframework-users
Hi

I see, perhaps this would help you https://pypi.org/project/rfhub2/


-Tatu
Send from my mobile

Tatu Aalto

unread,
Jul 27, 2021, 9:55:48 AM7/27/21
to Tomas Pekarovic, robotframework-users
Hi

But generally that pattern is problematic from IDE point of view,  because IDE doesn't know that there is new keywords available. I know that there are people who use that pattern successfully, but personally I have not liked that pattern because of the IDE problem. But it has many good sides too, like code encapsulation. 

I tend to build for each page or build library which had very few, ten or so, keywords. All the complexity is hidden from users. 

-Tatu
Send from my mobile
Reply all
Reply to author
Forward
0 new messages