Hi, community!
I'm new in bitbucket pipelines and also in behave, so any help I really appreciated.
I'm running behave BDD in bitbucket pipelines to execute 2 different features and is failing particularly the second one, in before_scenario method seems like it cannot create the driver or cannot open another session for the second time.
Is there any special code that I should include in the python script to run remotely when you want to execute more than one feature?
When I run only 1 feature the same pipeline script works perfectly.
This is the error:
pipelines:default:- step:name: TestBehaveimage: python:3.7.3script:- apt-get install unzip- pip install flask selenium requests behave- pip install webdriver-manager- behave -D env=testservices:- selenium-chromedefinitions:services:selenium-chrome:image: selenium/standalone-chromeenvironment:HUB_PORT_4444_TCP_ADDR: localhostHUB_PORT_4444_TCP_PORT: "4444"ports:- "4444:4444"
Hello @Daymi Morales Vega ,
Welcome to Atlassian Community!
The syntax you have used to define the service in your pipelines is slightly incorrect, as we currently don't support custom port mapping in service, we just currently support passing environment variables. The supported syntax and examples of defininig services in bitbucket pipelines can be checked in this documentation.
Having said that, I'm not very familiar with selenium itself, but from my research it seems that selenium by default allows only 1 concurrent session, and if you have more than one request, this request will be queued and timeout after a given amount of time if no slot becomes available.
Accordingly to selenium documentation, you can increase the session concurrency in the container, overriding the maximum limit, by setting both SE_NODE_MAX_SESSIONS to a desired number and SE_NODE_OVERRIDE_MAX_SESSIONS to true.
Alternatively, you also have the option to increase the time selenium waits before timing out when waiting for a slot. By default, a request will stay in the queue up to 300 seconds before a timeout is reached and an attempt to process the request is done every 5 seconds (by default). To change that you need to set the variables SE_SESSION_REQUEST_TIMEOUT and SE_SESSION_RETRY_INTERVAL
Please find below an example of bitbucket-pipelines.yml defining the selenium service to allow 2 concurrent sessions :
pipelines:
default:
- step:
name: TestBehave
script:
- sleep 15 # sleeps 15 seconds for the selenium service to start
- echo "This is a test to change selenium concurrency sessions"
services:
- selenium-chrome
definitions:
services:
selenium-chrome:
image: selenium/standalone-chrome
variables:
SE_NODE_OVERRIDE_MAX_SESSIONS: 'true'
SE_NODE_MAX_SESSIONS: '2'
This should make the selenium service to have 2 concurrent sessions available.
You can adjust the example above with your use case, and you also have the option to include the variables to change the session request timeout.
Hope that helps! Let me know in case you have any questions.
Thank you, @Daymi Morales Vega .
Kind regards,
Patrik S
Hi @Patrik S
Thanks for answering. It is a great explanation for the problem and you go deeper in the answer with an example. I also noticed that the port is not supported and I removed it from de pipeline, but thanks for highlighting that.
I will accept your answer because is well elaborated and It makes sense to fix the Session time-out issue by changing the Selenium setup.
However, in my case, I had already solved it in another way. I finally found a solution by slightly changing the behave implementation. I read deeply in the behavior environmental control documentation and I notice that there are methods that run only once per environment, and I put the driver creation there. With this change, Selenium does not need to create more than one session because all the tests are running in the same driver/browser. Basically, I had the driver creation wrongly in the before_scenario method instead of in before_all method.
Thank you again, I'm sure this will help others if they run into the same error.
Kind regards,
Daymi M.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey @Daymi Morales Vega ,
You're very welcome!
And thank you very much for sharing the solution that worked for you Happy to know that your selenium setup is working now :)
Kind regards,
Patrik S.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Daymi Morales Vega can you please post how you solved the issue and what you've adjusted in your pipeline? I'm also having the same issue. Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Patrik S your solution worked perfectly for me! I did manage to increase max sessions and all 5 tests PASSED on a bitbucket pipeline! While before it was always 1 passed and others failed to launch! Thanks a lot!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.