I just started with the robotframework and seleniumlibrary so i dont know if what i want to do is possible.
The setup: I have a website as a flask service that is run on a server, i have a SVN versioning and a Jenkins with robotframework setup to test one branch from SVN.
So i DO NOT want to test the released live website, i want to test the trunk (Development branch) before i tag it and make a new release published.
This means that i do not have the site i want to test live on a server, i run it locally as i develop on it. All test work if i start the flask app on localhost and run the test i have, but now i want to run them in jenkins instead without me having to start the flask app manually.
This is the flow i want to accieve if possible:
* Jenkins get informed of new version of trunk from SVN Hook
* Jenkins or robotframework prepares for the tests by starting the main.py flask app that the test should be run on
* Jenkins run the RobotFramework tests from the robot file that does testing against http://localhost:5005 (This is the config of the flask app that probably should be something else when started from robotframework or jenkings?)
* The tests is done and a report is made and the results published
* In the future automatically tag and release the site if the test is approved
This is the config of the flask app if run without a config (Port is 5005 in default config)
if __name__ == "__main__":
port = config['MonitorAndConfigure']['port']
app.run(debug=True, port=port, host='0.0.0.0')
With this flow i can publish my site and know it's working.
so the problem i have is the part where jenkins or robotframework should start the flask app and then close it again when the test is complete.
I have tried starting the flask app as a process in robotframework but it seems like it gets a temp path and port so the tests fail
Library Process
Suite Setup Start Process python ../main.py
... Wait for process
Suite Teardown Terminate All Processes
This is the first test:
*** Variables ***
${URL} http://localhost:5005
${BROWSER} headlesschrome
*** Test Cases ***
User can open the home page
[Documentation] As a user i can open the home page and see the site
open browser ${URL} ${BROWSER}
Wait Until Page Contains Systems Learch
Close Browser
CodePudding user response:
I solved this by running it as a shell buildstep and starting flask as a background service:
Xvfb :99 -screen 0 1024x768x24 &
export DISPLAY=:1
python3 main.py config_jenkins.json &
sleep 10
robot -d tests/results tests/test_website.robot
The python3 main.py config_jenkins.json &
runs the flask service as a background service during the test, the sleep was needed to give flask some time to start and publish the site.
For the robot framework to work with chrome inside jenkins i needed to make a dummy display with xvfb:
Xvfb :99 -screen 0 1024x768x24 &
export DISPLAY=:1
The chromedriver is installed inside the jenkins docker image and added to PATH. I also had to change the owner of google chrome to jenkins from root in the container so jenkins could start chrome without problems.