Package: robotframework-gevent
robotframework-geventRun keywords asynchronously with the power of geventinstallation:pipinstallrobotframework-geventUsage:# simple-test.robot*** Settings ***LibraryCollectionsLibraryStringLibraryGeventLibraryLibraryRequestsLibrary*** Test Cases ***Test1[Documentation]Simple test flow with gevent greenletsLogHello WorldCreate Gevent Bundlealias=alias1# Create a bundle of coroutinesSleep10salias=alias1# run your synchronous keyword# register all your keywords as coroutines to the gevent bundleAdd CoroutineSleep Wrapperalias=alias1Add CoroutineSleep20salias=alias1Add CoroutineSleep10salias=alias1Add CoroutineGEThttps://jsonplaceholder.typicode.com/posts/1alias=alias1Add CoroutineConvert To Lower CaseUPPER# Run your coroutines and get the values by order${values}Run Coroutinesalias=alias1Log Many@{values}# The 3rd coroutine was a request, take it's value${jsonplaceholder_resp}Get From List${values}3# assert the returned response code to be 200Status Should Be200${jsonplaceholder_resp}# assert that the returned `userId` field equals to 1Should Be Equal As Strings1${jsonplaceholder_resp.json()['userId']}*** Keywords ***Sleep WrapperSleep1sSee -Keyword Documentationrun test:>>> robot simple-test.robotPossible resultAfter test is completed go tolog.html:Owing to the fact that keywords are executed asynchronously, we cannot know the order of keyword execution, so instead they are printed in a table formatFor more examplesgo toexamplesMotivationModern software architecture isevent driven, with many background process.
Servers are being more pro-active instead of re-active as we see in aclient serverarchitecture.In order to test such systems, we need the ability to run coroutines in our test scripts.With the power ofgevent, we can run several coroutines in greenlets, so integrating them into our robotframework test script will provide super powers to our testing efforts!Why gevent?Concurrency can be achieved in 3 different ways:Multiprocessing - running each task in it's ownprocess.
The cons of such an approach would be massive consumption of resources, namely CPU and memory, as this means to allocate an entirememory heapto each task.
Another problem is a possible need forInter-Process Communication (IPC)that might be costly.Multithreading - running each task in athread.
Unlike multiprocessing, now all tasks run on the same memory heap and separated by threads, which the CPU coordinates usinground-robin.
However, python'sGlobal Interpreter Lock(GIL) prevents these threads from acting concurrently, it might perform context switching when IO operation occurs but there's no control for that.Asynchronous IO - running all tasks on a single thread, while IO operations won't block the progress of the program, while code execution is committed by anevent loopthatselectsbetween attachedcoroutines.
This is highly efficient in resources consumption when compared to multithreading and multiprocessing, but it requires some modifications to the original code.BlockingIO statements can hog the event loop and the code will not be concurrent.geventallows programmers to write seemingly regular "blocking" python code, but it will enforce asynchronous IO compliance bymonkey patchingFile structure|   LICENSE
|   .gitignore
|   .pylintrc
|   pyproject.toml
|   poetry.lock
|   README.md

|           
+---src
|   \---GeventLibrary
|       |   \---exceptions
|       |       |   __init__.py
|       |   \---keywords
|       |       |   __init__.py
|       |       |   gevent_keywords.py
|       |   __init__.py
|       |   gevent_library.py
|               
+---atests
|   |   __init__.robot
|   |   simple-test.robot
|   |   
|   \---utests
|       |   __init__.py
|       |   test_bundle_creation.pyCode stylingblackused for auto-formatting coderead,pylintused for code linting and pep8 complianceread,mypyused for type hintingread,robocopstatic code analyzer for robotframeworkread,perflintpylint extension for performance lintingreadcosmic-rayPython tool for mutation testingreadlinksRobotframeworkgeventContributors ✨Thanks goes to these wonderful people (emoji key):MalikMlitat📖This project follows theall-contributorsspecification. Contributions of any kind welcome!