From 5320adf47c9590df5ff53414d136a8f368b4e8a2 Mon Sep 17 00:00:00 2001 From: Web Access Date: Mon, 24 Mar 2014 17:07:10 +0530 Subject: [PATCH] Select2 function --- .../phpunit/CiviTest/CiviSeleniumTestCase.php | 34 +++++++++++++------ 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/tests/phpunit/CiviTest/CiviSeleniumTestCase.php b/tests/phpunit/CiviTest/CiviSeleniumTestCase.php index 364ffb77a6..5ef08991a9 100644 --- a/tests/phpunit/CiviTest/CiviSeleniumTestCase.php +++ b/tests/phpunit/CiviTest/CiviSeleniumTestCase.php @@ -364,22 +364,21 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { /** */ - function webtestFillAutocomplete($sortName, $fieldName = 'contact_1') { - $this->click($fieldName); - $this->type($fieldName, $sortName); - $this->typeKeys($fieldName, $sortName); - $this->waitForElementPresent("css=div.ac_results-inner li"); - $this->click("css=div.ac_results-inner li"); - $this->assertContains($sortName, $this->getValue($fieldName), "autocomplete expected $sortName but didn’t find it in " . $this->getValue($fieldName)); + function webtestFillAutocomplete($sortName, $fieldName = 's2id_contact_id') { + $this->select2($fieldName,$sortName); + //$this->assertContains($sortName, $this->getValue($fieldName), "autocomplete expected $sortName but didn’t find it in " . $this->getValue($fieldName)); } /** */ function webtestOrganisationAutocomplete($sortName) { - $this->type('contact_name', $sortName); - $this->click('contact_name'); - $this->waitForElementPresent("css=div.ac_results-inner li"); - $this->click("css=div.ac_results-inner li"); + $this->clickAt("//*[@id='s2id_contact_id']/a"); + $this->waitForElementPresent("//*[@id='select2-drop']/div/input"); + $this->keyDown("//*[@id='select2-drop']/div/input", " "); + $this->type("//*[@id='select2-drop']/div/input", $sortName); + $this->typeKeys("//*[@id='select2-drop']/div/input", $sortName); + $this->waitForElementPresent("//*[@class='select2-result-label']"); + $this->clickAt("//*[@class='select2-results']/li[1]"); //$this->assertContains($sortName, $this->getValue('contact_1'), "autocomplete expected $sortName but didn’t find it in " . $this->getValue('contact_1')); } @@ -1876,4 +1875,17 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { } return $return; } + + /** + * function to type and select first occurance of autocomplete + */ + function select2($fieldName,$label) { + $this->clickAt("//*[@id='$fieldName']/a"); + $this->waitForElementPresent("//*[@id='select2-drop']/div/input"); + $this->keyDown("//*[@id='select2-drop']/div/input", " "); + $this->type("//*[@id='select2-drop']/div/input", $label); + $this->typeKeys("//*[@id='select2-drop']/div/input", $label); + $this->waitForElementPresent("//*[@class='select2-result-label']"); + $this->clickAt("//*[@class='select2-results']/li[1]"); + } } -- 2.25.1