2.9.16
Coherent GT
A modern user interface library for games
Test driver support

Coherent GT provides a webdriver for performing tests on the UI of your application.

Prerequisites

  • PhantomJS needs to be installed on your machine in order for the Test Driver to run.
  • The pages to be tested should include the "coherent.js" script.
  • "TestDriver.dll" should be present in the folder containing the executable of your application. The "test_driver" folder should also be included there unless you have explicitly set a different location for it via Coherent::UIGT::SystemSettings::TestDriverResourcesFolder.

Usage

To use the Test Driver with your application the Coherent::UIGT::SystemSettings::TestDriverPort structure should be set to a port number where the Test Driver can connect. In the sample applications this is facilitated via the --webdriver= command line argument.

A system listener can be set using the application's SetSystemListener method. If the listener implements CreateView it should return the view that the test driver will listen for events on and use for tests, otherwise a new view will be created. Once the test is completed the listener's TestRunDone method is called which can be used to close the application for example. Here is how they are implemented in our samples:

virtual Coherent::UIGT::View* CreateView(const Coherent::UIGT::ViewInfo& , const char* url)
{
auto view = m_Application->GetView();
if (url)
{
view->LoadURL(url);
}
return view;
}
virtual void TestRunDone() override
{
m_Application->Quit(0);
}
void SetApplication(SampleApplicationBase* app) override
{
m_Application = app;
}

Running tests

Tests can be run using the Selenium WebDriver API. It is important to initialize PhantomJS with the path to the executable you wish to test and a port number and to also set the appropriate working directory. The names of the test methods should begin with test. The following Python example demonstartes a test that checks that the loaded page contains 'Document' in its title:

import selenium
import selenium.webdriver
import unittest
class GTTestCase(unittest.TestCase):
def setUp(self):
self.browser = selenium.webdriver.PhantomJS(executable_path=r'path_to_executable', port=8910, desired_capabilities = {})
def tearDown(self):
self.browser.quit()
return super(GTTestCase, self).tearDown()
def test(self):
self.assertIn('Document', self.browser.title)
if __name__ == '__main__':
unittest.main(verbosity=2)