TestUI (Java) commands

Loadero uses TestUI (Java) and Selenium Nightwatch to handle participant action simulation.

TestUI documentation can be found here.

TestUI offers a lot of their own commands to handle interaction with browser. Full feature support for TestUI is still in progress.

Available imports from TestUI

  • testUI.UIOpen.open
  • testUI.UIUtils.putLog
  • testUI.Utils.AppiumHelps.sleep
  • testUI.Utils.By.*

Available script variables

Loadero offers some variables that can be accessed in script. These variables hold information relevant to the participant that is executing test. Variables are available through globalConfig variable.

  • globalConfig.getParticipant().getId() (Integer): ID of participant that is executing test. This ID is unique inside group
  • globalConfig.getParticipant().getName() (String): name of participant as defined in participant configuration
  • globalConfig.getGroup().getId() (Integer): ID of group in which participant is executing test. This ID is unique within test run
  • globalConfig.getGroup().getName() (string): name of group as defined in group configuration
  • globalConfig.getRun().getId() (Integer): ID of this test run
  • globalConfig.getTest().getName() (String): name of current test
  • globalConfig.getNetwork() (String): network conditions of this participant
  • globalConfig.getBrowser() (String): browser version used
  • globalConfig.getMediaType() (String): media type of simulated audio/video feed
  • globalConfig.getLocation() (String): region where current participant is located

Script examples

Locating elements

By using CSS selector

UIElement element = E(byCssSelector("your.Id"));

By using ID

UIElement element = E(byId("your.Id"));

By using xpath

UIElement element = E(byXpath("//some"));

It is possible to use all strategies by switching back and forth.

[!EXAMPLE]

public void test() {
   open("https://appr.tc/")
      // Wait for page to load up
      .setElement(byCssSelector("body")).waitFor(10).untilIsVisible()
      // Find join button and click on it
      .setElement(byId("join-button")).click()
   // Wait for 10 seconds
   sleep(10 * 1000);
}
public void testGoogleSearch() {
  open("https://www.google.com")
    // Wait for page to load up
    .setElement(byCssSelector("body")).waitFor(10).untilIsVisible()
    // Find search bar
    .setElement(byCssSelector("input[type=text]"))
    // Type 'loadero' in it
    .sendKeys("loadero")
    // Find search button and click it
    .setElement(byCssSelector("input[value~='Google']")).click();
}

Using TestUI Element Assertion methods

element.(shouldBe()/shouldHave())
          (.not())
              .visible()
              .enabled()
              .Exists()
              .exactText("someText")/containText("")/containNoCaseSensitiveText("")
              .value("someValue")
              .attribute("attributeName").equalTo("value")
              .theAttribute("attribute")
element.waitFor(timeInteger)
          .untilIs(Not)Visible()
          .untilIs(Not)Enabled()
          .until(Not)Exist()
          .untilHas(Not)Text("someText")
          .untilHas(Not)Value("someValue")
          .untilHas(Not)Attribute("someAttribute")

You can find detailed descriptions and more examples in TestUI wiki


Custom commands

Set file into file input field

setFile(By selector, String fileName);

Allows to set one of Loadero sample files into file input field.

The selector parameter specifies input field element selector, e.g. input[type="file"], input#file-upload.

The fileName parameter specifies chosen file name.

Available test files

For now, one of predefined test files can be chosen. Available files:

File name (fileName) Type Size
loaderoSample100KB.png PNG 100KB
loaderoSample1MB.png PNG 1MB
loaderoSample5MB.png PNG 5MB
loaderoSample30MB.png PNG 30MB
loaderoSample100MB.txt TXT 100MB

In case there is a need for other file format or size, feel free to contact us.

[!EXAMPLE]

public void testUIWithLoadero() {
  open("http://www.toledorocket.com/perftest/uploadtest/fileselect.asp")
      .setElement(byCssSelector("body"))
      .waitFor(10).untilIsVisible();

  setFile(byCssSelector("input[type=FILE]"), "loaderoSample100KB.png");
  sleep(1000);

  E(byCssSelector("body")).saveScreenshot("fileSet.png");
}


Set User-Agent

setUserAgent(String userAgent);

Changes User-Agent header for outgoing requests. To switch back to original user agent, call the function with empty value.

The userAgent parameter specifies prefered User-Agent header value.

[!EXAMPLE]

public void testUIWithLoadero() {
  // Open page and create screenshot with default User-Agent
  open("https://www.whatismybrowser.com/detect/what-is-my-user-agent")
      .setElement(byCssSelector("body"))
      .waitFor(10).untilIsVisible()
      .saveScreenshot("UADefault.png");

  // Set custom User-Agent header
  setUserAgent("Custom_User_Agent");

  // Refresh page
  WebDriverRunner.getWebDriver().navigate().refresh();

  // Wait for page to load and create screenshot with changed User-Agent
  E(byCssSelector("body"))
      .waitFor(10).untilIsVisible()
      .saveScreenshot("UAchanged.png");

  // Reset User-Agent header to default value
  setUserAgent("");

  // Refresh page
  WebDriverRunner.getWebDriver().navigate().refresh();

  // Wait for page to load and create screenshot with default User-Agent
  E(byCssSelector("body"))
      .waitFor(10).untilIsVisible()
      .saveScreenshot("UAreset.png");
}


Update network conditions during test

updateNetwork(String networkMode);

Updates network conditions for participant while the test is running.

The networkMode parameter specifies what network conditions should be used. Available network configurations and networkMode parameter values can be found here.

[!EXAMPLE]

public void testUIWithLoadero() {
  open("https://google.com")
      .setElement(byCssSelector("body"))
      .waitFor(10).untilIsVisible();

  // Update network condition to 4g value
  updateNetwork("4g");
}

results matching ""

    No results matching ""