phpunit-selenium
phpunit-selenium copied to clipboard
Webdriver(Selenium2) - Class 'Keys' not found
Hi guys,
I need to press PAGEDOWN key physically in order to scroll a long window down,
and wrote a function as following:
public function scrollWindowDown(){
$this->keys(Keys::PAGEDOWN);
return true;
}
part of my script:
// click some element on the page ,just to make sure that the focus is on the page
$this->byCssSelector('div[class="title doc-color-green"]')->click();
//want to press PAGEDOWN key.
$this->scrollWindowDown();
When I execute my script with phpunit , there's an error: PHP Fatal error: Class 'Keys' not found in C:\sysTest\lib\rongSysTest.php on line 111 ps: rongSysTest.php is a api encapsulation lib of my own, extended from PHPUnit_Extensions_Selenium2TestCase. it contains the scrollWindowDown() method.
I viewed this file: https://github.com/sebastianbergmann/phpunit-selenium/blob/a7401a04755dce41332a450b7111dd610caa3ace/PHPUnit/Extensions/Selenium2TestCase/Keys.php
and changed the parameter directly like this:
public function scrollWindowDown(){
$this->keys("\xEE\x80\x8F");
return true;
}
This function didn't report an error ,but after it's executed, the page didn't perform a pagedown behavior as expected.
I can't find out what the problem is ,Please help, thanks
The name of the class is actually PHPUnit_Extensions_Selenium2TestCase_Keys, so you have to use PHPUnit_Extensions_Selenium2TestCase_Keys::PAGEDOWN because of the legacy namespaces. But no idea if the scrolling should work that way because I never had such a use case. The webdrivers scroll themselves when you perform a click event (or similar) on an element that is currently out of view.
hi, Thanks for your help @julianseeger , I did some tests according to your advice.
environment:
- Selenium 2.39 Standalone Driver/Server
- PHP 5.4.11
- PHPUnit 3.7.28
- Chrome V31 & ChromeDriver v2.7
- Firefox v20
I attached two screenshots for reference, as you see ,there's some select-list item out of view at Step2.
page link( Chinese) : http://beijing.rong360.com/p_3f8b9lfk1?st=1&at=12&aq=5&te=0.47&me=4560&application_type=9&from=search&pos=2&fpid=8b040c614d5296484176874ba6c28c23&uf=s_910ca90add8c7db5e2f37bbe007e8279
Step1:
Step2:

Problem1: When I ran script with firefox, it scroll the frame automatically at Step 1, at Step2, it didn't scroll down. I also tried a new version - firefox v27. It has the same problem. But Chrome scrolls the frame automatically at all steps.
Problem2:
I modified my function as julian's advice :
public function scrollWindowDown(){
$this->keys(PHPUnit_Extensions_Selenium2TestCase_Keys::PAGEDOWN);
return true;
}
It still didn't work at Step2.
Since my purpose is regression testing for core features based on ui, it's ok to run my tests all on chrome. I'd prefer keeping this issue open , and do more experiments later , try to find out the cause.
Could you try $this->moveto($theSelectElement); instead to get to it; that should offer a better guarantee that the element will be in the viewport.