Skip to content

Methods

Yevhen edited this page Nov 3, 2018 · 20 revisions

Editor

Static class that contains method to interact with UnityEditor

Note: methods of the class are available only if tests are executed in UnityEditor

Methods:

  • public static void StartPlayMode() => Starts PlayMode in Editor;
  • public static void StopPlayMode() => Stops PlayMode in Editor;

Game

Static class that contains method to interact with Game itself

Note: methods of the class are available only if a Game is started. You can't use it in Edit Mode of the Editor

Methods:

  • public static void MakeScreenshot(string fileName, string folderName) => Make screenshot of a game and save it to Directory.GetCurrentDirectory() + folderName with name fileName.png. If folderName is not exist, than will create it;
  • public static void MakeScreenshot(string fullPath) => Make screenshot if a game and save it to path that declared. fullPath argument should contant full path + name of the screenshot with resolution (like *.png). The method won't create folder if it isn't exist, so you should create by yourself;

GameObject

Class that contains method to interact with a GameObject

Note: use this class to interact with some GameObject of the application

Methods:

  • public GameObject FindByUPath(string upath) => Sets Upath locator that will be used to find the GameObject and return its instance;
  • public GameObject FindByName(string root, string name) => Sets root element and name of the GameObject that will be used to find the GameObject. Root element should be active in hierarchy, otherwise that element wan't be found. The GameObject is descendant of the root element (not only direct child);
  • public GameObject FindByNameAndParent(string root, string name, string parent) => Sets root element, parent element and name of the GameObject. Unity will search for root element (should be active in hierarchy), then will search for parent name (could be active and inactive in hierarchy + parent is descendant) and finally will search for GameObject with given name (could be active and inactive in hierarchy + the gameObject is descendant of parent element);
  • public bool Exists => property that returns result if the GameObject is exist in the hierarchy;
  • public bool IsActiveInHierarchy => property that returns result if the GameObject is active in the hierarchy. NoSuchGameObjectException may be occurred if the gameObject is not existed. Need to be sure that the element is exist, before check if it is active in hierarchy;
  • public bool IsRendering => property that returns result if the GameObject is rendering (gameObject.GetComponent().isVisible). NoSuchGameObjectException may be occurred if the gameObject is not existed;
  • public bool IsOnScreen => property that returns result if the GameObject is on the screen (by coordinates) but is not guaranteed that any other gameObject is not overlap the GameObject. NoSuchGameObjectException may be occurred if the gameObject is not existed;
  • public bool IsGraphicClickable => property that returns result if the GameObject is clickable, checking Graphically (the gameObject is on the screen and Ui.Graphic.RayCast is hit the element first, so no other UI element is overlap the gameObject). NoSuchGameObjectException may be occurred if the gameObject is not existed;
  • public int Count => returns number of GameObjects with given locator, if any gameObject was found, Count would be 0;
  • public void Click() => emulates Click on first gameObject that was found by set locator;
  • public void SendKeys(string value) => sets value to Input of the GameObject (gameObject.GetComponent().text = value) that was found by set locator;
  • void Swipe(Constants.Directions direction) => emulate Swipe to selected direction (Up, Down, Left or Right) from center of the gameObject that was found by set locator;
  • string GetComponent(string component) => returns json of given component. NoSuchGameObjectException may be occurred if the gameObject is not existed;
  • ScreenCoordinates GetCoordinates() => returns 2d coordinates of the gameObject. NoSuchGameObjectException may be occurred if the gameObject is not existed;
  • void Should(Condition condition, int timeoutMs) => Checks with set timeout a condition (like Should(Be.ActiveInHierarchy)). Will wait timeoutMs until given conditon is fulfilled or timeoutMs has expired;
  • void Should(Condition condition) => calls void Should(Condition condition, int timeoutMs) and uses Configuration.TimeoutMs as set timeoutMs;
  • void ShouldNot(Condition condition, int timeoutMs) => Checks with set timeout a condition is not fulfilled (like ShouldNot(Be.ActiveInHierarchy)). Will wait timeoutMs until given conditon is not fulfilled or timeoutMs has expired;
  • void ShouldNot(Condition condition) => calls void ShouldNot(Condition condition, int timeoutMs) and uses Configuration.TimeoutMs as set timeoutMs;
Clone this wiki locally