Last active
December 18, 2015 16:09
-
-
Save akovalyov/5809845 to your computer and use it in GitHub Desktop.
Selenium interaction with Chozen plugin in Codeception
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Codeception\Module; | |
// here you can define custom functions for WebGuy | |
/** | |
* Class WebHelper | |
* @package Codeception\Module | |
*/ | |
class WebHelper extends \Codeception\Module | |
{ | |
/** | |
* @param \WebGuy $I | |
* @param $locator string XPath of li element which actually should be selected shown in the chozen list | |
* @desc Chozen plugin does not support click trigger, only mousedown, that is why we need to refer to low-level | |
* API of Selenium | |
*/ | |
function clickChzn(\WebGuy $I, $locator) | |
{ | |
/** | |
* @todo here we should check which module is currently used by Codeception | |
* Maybe it is better to call an executeJs method which is supported by both Selenium and ZombieJS | |
* like | |
* $I->executeJS('$('.$locator.').mousedown()') | |
* if jQuery or Zepto is used | |
* didn't check with Prototype | |
* Note, that in fact here XPath is passed, not a Sizzle-like selector | |
* It is no reason to try to write this function on vanilla JS - Chozen won't work without jQuery/Prototype | |
*/ | |
$I->executeInSelenium(function (\Selenium\Browser $browser) use ($locator) { | |
//active the whole chozen list | |
//i assume that id of chozen is some_blablaId and id of chozen list item is some_blablaId_o_valueOfOption | |
//@see AbstractChosen.prototype.result_add_option method | |
$browser->mouseDown(preg_replace("/_[a-z]_[0-9]/", '', $locator)); | |
$browser->mouseUp($locator); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment