Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


SessionNotCreatedException: New session request timeout error executing behave from pipeline

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:

HOOK-ERROR in before_scenario: SessionNotCreatedException: Message: Could not start a new session. New session request timed out
My pipeline looks like this: 
      - step:
          name: TestBehave
          image: python:3.7.3      
            - apt-get install unzip
            - pip install flask selenium requests behave
            - pip install webdriver-manager
            - behave -D env=test
            - selenium-chrome
      image: selenium/standalone-chrome
        HUB_PORT_4444_TCP_ADDR: localhost
        HUB_PORT_4444_TCP_PORT: "4444"  
        - "4444:4444"            
Thanks in advance! 

1 answer

1 accepted

0 votes
Answer accepted
Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
Jul 12, 2022 • edited Jul 13, 2022

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 : 



      - step:

          name: TestBehave     


            - sleep 15 # sleeps 15 seconds for the selenium service to start
- echo "This is a test to change selenium concurrency sessions"


            - selenium-chrome




      image: selenium/standalone-chrome  




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. 

Like Patrik S likes this
Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
Jul 13, 2022

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.

@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

Like Yvonne Waterman likes this

Suggest an answer

Log in or Sign up to answer
Site Admin
AUG Leaders

Atlassian Community Events