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

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

Avatar

1 badge earned

Collect

Participate in fun challenges

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

Challenges
Coins

Gift kudos to your peers

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

Recognition
Ribbon

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!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,463,829
Community Members
 
Community Events
176
Community Groups

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: 
pipelines:
  default:
      - step:
          name: TestBehave
          image: python:3.7.3      
          script:                
            - apt-get install unzip
            - pip install flask selenium requests behave
            - pip install webdriver-manager
            - behave -D env=test
          services:
            - selenium-chrome
definitions:
  services:
    selenium-chrome:
      image: selenium/standalone-chrome
      environment:
        HUB_PORT_4444_TCP_ADDR: localhost
        HUB_PORT_4444_TCP_PORT: "4444"  
      ports:
        - "4444:4444"            
 
Thanks in advance! 

1 answer

1 accepted

0 votes
Answer accepted

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. 

Like Patrik S likes this
Patrik S Atlassian Team 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

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Site Admin
TAGS

Atlassian Community Events