Coherent GT provides a webdriver for performing tests on the UI of your application.
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:
{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;}
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 seleniumimport selenium.webdriverimport unittestclass 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)