Skip to content

How to write first test

Yevhen edited this page Jan 8, 2019 · 3 revisions

Editor Based testing

How To Set Up Puppetry Environment

Methods

  1. Be sure that Puppetry.Puppeteer nuget package is installed

  2. Set all needed configuration by Set(Settings setting, object value) in TestRun initialization (OneTimeSetUp). No need to set them every test as it is static properties that will be used in every test.

  3. Call Editor.StartPlayMode() in Test Initialization (SetUp) to start PlayMode in the Editor.

  4. Describe all game objects that will interact with, in Arrange/Given part of a test or in ScreenObject class (adaptation of PageObject pattern). Example of initializing: var button = new GameObject("RootElement", "GameObjectName");

  5. Make actions with initialized game objects in Act/When part of a test. Example: button.Click(); Note: Be sure that the game object is exist in the hierarchy, before you interact with it to avoid NoSuchGameObjectException (use Should(Be.Present) before the action).

  6. Check result of a test in Assert/Then with Should/ShouldNot methods of needed game object. Example: menuLabel.Should(Be.Present); menuLabel.Should(Be.ActiveInHierarchy);

  7. In Test clean up method (TearDown) if test result is failed, call Game.MakeScreenshot() to create and save screenshot with the game, to check why test is failed.

  8. Call Editor.StopPlayMode(); in Test clean up method (TearDown) to stop play mode.

  9. Call Driver.KillAllSessions(); in Test run clean up (OneTimeTearDown) to kill all sessions that were created.

Game Based testing

  1. Add GameObject with component "InGameApiClientLoader" to start connection with Puppetry.PuppetryDriver
  2. Launch the game to initialize Puppet of Puppetry.
  3. Write scenario of test that want to execute (to stop and to start game again, you should launch it on the device/platform again). It is more difficult to write isolated tests