TestProject Forum

Run different browsers at the same time

Hi. I am currently running several test using TP Agent, all running in a single browser window. For this particular case I need two separate browsers to run and interact with each other (one “student-browser” browser would simulate a student taking an exam and the oner one “proctor-browser” would simulate a proctor authorising and supervising the student). The flow implies the student asking for authorisation in student-browser, then the proctor confirming in proctor-browser. This interaction needs to be synced since the proctor needs to wait the student to ask for permission and then the student waits the proctor to grant it. Then the flow includes some other interactions between the two browser windows.
I was able to open a FF browser and a Chrome browser, each of them displaying different pages by using “vanilla” Selenium webdriver, but when I try to do the same with TP webdriver I get:

if BaseDriver.__instance is not None:
    raise SdkException("A driver session already exists")
    src.testproject.sdk.exceptions.sdkexception.SdkException: A driver session already exists

This is my initial sample code for managing more than one browser at a time:

def test_multiple_browsers():
    ff_driver = webdriver.Firefox(token=settings.tp_token)
    ff_driver.report().disable_auto_test_reports(disabled=True)
    ff_driver.report().disable_command_reports(disabled=True)

    driver = webdriver.Chrome(token=settings.tp_token)
    driver.report().disable_auto_test_reports(disabled=True)
    driver.report().disable_command_reports(disabled=True)
    ff_driver.get("http://google.com")
    driver.get("http://yahoo.com")

Did anyone face this before? Any help would be more than appreciated.
Thanks in advance

Hello @federico.giraldi,

Currently using the local agent you can only run one test at a time,
however this can be solved by spinning up multiple docker agents
To run coded tests using TestProject’s Open SDK on docker agents you will have to create yaml file as described in here:

https://hub.docker.com/r/testproject/agent

The Open SDK configuration is at the end of this document.

After you configured your yaml file correctly, you will need to spin the container by using:

docker-compose -f <file_name> up -d

After the container is up, you can run your code and it should execute on the Dockerized agent.
Note that if you configured a port that is different from 8585, you will have to change the: TP_AGENT_URL environment variable in your code.

You can also define multiple docker agents in your yaml file, each agent will be with a different port(each docker agent is a different service essentially), here is an example:

If you want to run your python scripts using Docker agents in an ephemeral way, you can do it by running those tests in a pipeline as described in this document:

Using OpenSDK within CI/CD

Hey @artem.kuznetsov ! Thanks for your quick and detailed reply. Unfortunately this doesn’t solve my problem. What I need is to be able to handle 2 webdriver instances at the same time doing different stuff and synchronize their efforts. I have taken a look to the webdriver class and I see it uses a singleton approach, so it looks this is a dead end. It raises an SdkException (here python-opensdk/basedriver.py at master · testproject-io/python-opensdk · GitHub for reference)
So, to my understanding it looks like there is no way to create more than one instance of a webdriver when testing with the SDK. Is that correct? I don’t need more agents, I just need more than one webdriver