Muse Examples

These examples are intended to show the capabilities of some of the steps and value sources included with the Muse Test Framework. If you have Muse installed, you can run all the examples like this:
  muse run suite-all
It will take several seconds for the project to load, then the tests will execute. If you have firefox installed, it will open twice, to run examples 6 and 7. Example 8 will fail until you build the custom step (see below).

The descriptions here are intended only as a high-level overview. To best understand the examples, open each example with the MuseIDE and step through it to see how it works.

For example:
  muse edit ex1-GetAndSetVariable-Verify-Equals.json

1 - Variables, Verify, Equals

Demonstrates how to set a variable and verify a variable is equal to another value.

2 - If, Less than, Log message

Demonstrates conditional logic flow: Sets a variable. Then, if the variable is less than a larger number, log a message to the event log.

3 - While, Increment

Implements a loop using a while step with a variable comparison. The end result is sending a message to the event log 3 times.

4 - Call a Macro

Shows how to call a macro. The macro increments a variable set by the caller and the result is checked after the macro is complete. Open add5Macro.json file to see how the macro is implemented.

5 - Call a Function

Demonstrates how to call a function with parameters and then check the return value. It also demonstrates variable scoping. Variable counter is set by the caller, but is not visible in the function. Variable var1 is set in the function, but is not visible to the caller. Open variableScopingFunction.json to see how the function is implemented.

6 - Project resources, WebDriver, Browser control, Parameterized test with defaults

This test opens a browser, visits the Github site, enters a loop to search for the Muse project, then on the 3rd try, follows the first project link and then continues to the project wiki.

  1. Opens a browser. It references two project resources, which provide the browser type (desired capabilities) and the source for the driver provider. The capabilities resource is compatible with Selenium/WebDriver browser capabilities parameters. See the firefox.json and local-provider.json files for reference. remote-provider.json shows how to connect to a remote provider.
  2. Go to the Gihub site
  3. Loop 3 times: call a function to enter a search term and execute the search. Note that the function references variables search1...search3 which are not set in the test. The test expects them to be provided in the test context when it is run. Default values are provided in the test (look at the Parameters tab in MuseIDE).
  4. After the loop is complete, visit the project, then the wiki
  5. Close the browser

7 - Element locator re-use

Demonstrates how element locators may be defined in one place and referenced from many places to avoid duplication. The click step references a locator defined in github-homepage.json.

8 - Using a custom step (Java)

This test calls a custom step defined in the project. It passes 3 parameters to it, which the custom step writes to the event log. The custom step is implemented in Java - Look for ExampleCustomStep.java under the src folder. To run this test successfully, you must first build the custom step, which requires Java JDK 8 and Gradle on your path. If you have those, run gradle build in the examples folder.

9 - Using a custom step (Javascript)

This test calls a custom step defined in the project. It passes 2 parameters to it (abc and xyz). The custom step is implemented in Javascript (example-js-step.js). The test sets two local variables (string1="value1" and int1=17) and passes in two parameters (abc="aaa" and xyz=true). The custom step fails if the the "xyz" paramter evaluates to false or if the string1 variable is not "value1". If then appends "+" and the value of the abc parameter to the string1 value and sets string1 to this new value. It also multiples the int1 variable by 2. After returning, the test then verifies the changes to variables string1 and int1.

10 - Parameterized test suite

This test expects a parameter: the text of a link to click. The test has a default value for this parameter (for use during test development - it is used when running the test in MuseIDE). The "ex10-suite" test suite contains three values for this parameter, and therefore runs the test 3 times. Run the suite with:
muse run ex10-suite

11 - Project variables

This test demonstrates the use of project-level variables. It expects two parameters (browser and browser-provider). Unlike the previous example, they are not defined in the default variables for the test (Parameters tab). Instead, they are defined as project-level varaiables (see project-vars.json). The variables are expected to provide a browser configuration (#"firefox" --> firefox.json) and browser provider (#"local-provider --> local-provider.json) that is used to open the browser.

12 - Inject javascript

Demonstrates executing JavaScript in the browser using the Run Javascript step.