Run Canopy tests in parallel

I am using Canopy to run my tests, I was looking at running them in parallel so I set parallel flag to true in the config but it doesn’t seem to work. Could someone point me to a sample showing how to run tests in parallel?

Other thing I was looking at was to do some stress test by running multiple instances of chrome, could someone help me with that as well.

Hi @sandeepc24, there is a good example in the repo that you can use as a starting point:

The key concept is that the functions in the canopy.parallell.functions module all take a browser instance in the last position, so you can use normal functions like url, and just pass in an instance.

The other way you can use it is to instantiate a browser and use instance methods.

Both ways are shown in the functionsTests.fs and instanceTests.fs files respectively.

Hi Chethusk, thanks for the pointers. I tried using instance methods but it doesn’t work with Expecto. Only one test passes and the others seem to hang with following error

canopy.types+CanopyNoBrowserException: Can't perform the action because the browser instance is null.  `start chrome` to start a new browser.

Here is my test code

let startBrowser() =
    let browser = new Instance()
    browser.start Chrome // Use this if you want to see your tests in the browser
    //start ChromeHeadless
    browser.resize (1280, 960)

let startApp (browser : Instance)=
    browser.url serverUrl

let login (browser : Instance) =
    let logout = browser.someElement logoutLinkSelector 
    if logout.IsSome then logoutLinkSelector 
        browser.waitForElement loginLinkSelector loginLinkSelector

    "#email" << username
    "#password" << password "Login"
    browser.waitForElement logoutLinkSelector

let logout (browser : Instance) = logoutLinkSelector

let tests = 
    testList "client tests" [
        testCase "sound check - server is online" 
        <| fun () ->
            let browser = startBrowser()
            startApp browser

        testCase "login with test user" 
        <| fun () ->
            let browser = startBrowser()
            startApp browser
            login browser
            logout browser

        testCase "login go to profile"
        <| fun () ->
            let browser = startBrowser()
            startApp browser
            login browser
            logout browser

I set the parallel flag to false and even then the tests don’t run with Instance method.

I have figured out what was wrong. I was using << instead of browser.write which was expecting the global browser and was failing on it.

Now I can get my tests to run but I still don’t see multiple instances of chromedriver.exe in my task manager which I think means the tests aren’t running in parallel, is this correct?

Glad you got them running! Is there a repo up that I can pull down and try as well?

I’ll try and create a sample to share it with you.

You can download the SAFE project and run the tests.

I have modified my Runner.fs as shown below

module UITests.Runner

open System.IO
open canopy
open canopy.classic
open canopy.runner.classic
open canopy.types
open Expecto
open System.Diagnostics
open System

let main args =
            runTestsWithArgs { 
                defaultConfig with 
                    ``parallel`` = true
                    // ``parallelWorkers`` = 5
                    // ``stress`` = Some (TimeSpan.FromMinutes(1.))
             } args Tests.tests
        with e ->
            printfn "Error: %s" e.Message