1

I'm using Quamotion and Pester to test my mobile app.

Right now, I find myself having to repeat a lot of parameters (such as usernames and passwords) which I use in my tests.

Is there any way to use global variables in Quamotion/Pester tests?

1 Answers1

2

You define global variables in Pester by prefixing them with $script:. Global variables are normally defined at the top of your script.

For example, here's a test which logs in to your app and stores the username as a variable:

$script:username = "myuser"

Describe "My App" {
    it "Login" {
        $usernameTextField = Find-Element -xpath "//XCUIElementTypeTextField[@name='username']"
        Set-Value -elementId $usernameTextField -value $script:username

        $loginButton = Find-Element -xpath "//XCUIElementTypeButton[@name='Login']"
        Click-Element -elementId $loginButton
    }
}

Hope it helps!

Frederik Carlier
  • 4,606
  • 1
  • 25
  • 36