script to convert robot tests to python
- [ ] imports
- [X]
Libraryimports - [ ] aliased
Libraryimports - [ ]
Resourceimports - [ ] don't use
*imports aka resolve imported keywords (hard)
- [X]
- [ ] control flow
- [ ] if statements
- [ ] for loops
- [ ] while loops
- [ ] try/except
- [ ] fix cli output
- [ ] keyword -> function calls
- [X] args
- [ ] kwargs
- [ ] keyword definitions
- [ ] resolve keywords and convert types instead of assuming
stron everything (hard)
- [ ] special cased builtin keywords
- [X]
no operation->... - [ ]
log->logger.info/logger.warn/etc - [ ]
run keyword and ___ error->try/except
- [X]
- [ ] tags -> markers
- [ ] docstrings
- [ ] module level (suite)
- [ ] package level/init file or whatever (suite)
- [ ] keywords
- [ ] tests
- [ ] variables
- [ ] normal
- [ ] list
- [ ] dict
chatgpt seems to be pretty good at doing this in my experience. here's an example prompt and the response it gave me:
prompt
convert the following robotframework code to python using pytest.
*** Settings *** Documentation A test suite for valid login. ... ... Keywords are imported from the resource file Resource keywords.resource Default Tags positive *** Test Cases *** Login User with Password Connect to Server Login User ironman 1234567890 Verify Valid Login Tony Stark [Teardown] Close Server Connection Denied Login with Wrong Password [Tags] negative Connect to Server Run Keyword And Expect Error *Invalid Password Login User ironman 123 Verify Unauthorised Access [Teardown] Close Server Connectionwhen converting keywords, import
keywordfrom thepytest_robotframeworkmodule and decorate them with@keyword
answer
To convert the given Robot Framework code to Python using pytest and the
pytest_robotframeworkmodule, you can follow the steps below. Note that thepytest_robotframeworkmodule is not a standard module, and I'm assuming you have a module with that name or a similar one that provides the necessary functionality.
Install the
pytestandpytest_robotframeworkmodules if you haven't already:pip install pytest pytest_robotframeworkCreate a Python module, for example,
test_login.py, and write the following code:import pytest from pytest_robotframework import keyword @keyword def connect_to_server(): # Implementation for connecting to the server pass @keyword def login_user(username, password): # Implementation for logging in a user pass @keyword def verify_valid_login(expected_username): # Implementation for verifying a valid login pass @keyword def verify_unauthorized_access(): # Implementation for verifying unauthorized access pass @keyword def close_server_connection(): # Implementation for closing the server connection pass @pytest.mark.positive def test_login_user_with_password(): connect_to_server() login_user("ironman", "1234567890") verify_valid_login("Tony Stark") close_server_connection() @pytest.mark.negative def test_denied_login_with_wrong_password(): connect_to_server() with pytest.raises(Exception, match="*Invalid Password"): login_user("ironman", "123") verify_unauthorized_access() close_server_connection()Run the tests using pytest:
pytest test_login.pyThis example assumes that you have implemented the actual functionality for connecting to the server, logging in a user, verifying a valid login, verifying unauthorized access, and closing the server connection. Replace the placeholder comments with the actual implementation according to your application.