際際滷

際際滷Share a Scribd company logo
Selenium and PHP By  Alexander Manuhin , QA Manager  Adyax  仂于舒 亢亳亰仆  WebDriver  亳  PHP .  仂 舒亰舒弍仂从亳 亠亶仄于仂从舒 亟仂 仂亞舒仆亳亰舒亳亳 仗仂亳亰于仂亟于亠仆仆仂亞仂 仗仂亠舒.
40 big websites in 2011 www.adyax.com
PHP+WebDriver 于仂仂亠    亟舒仆亳亠
PHP  于 从舒亠于亠  binding  亟仍  WebDriver  ?
丼仂 仆亠仂弍仂亟亳仄仂 亟仍 亠舒仍亳亰舒亳亳     PHP binding  ? Object model TestSuit Protocol
Json Wire Protocol  从舒从 仂 舒弍仂舒亠 ? Json Wire Protocol -  JSON 亠亠亰 HTTP 舒仗仂 于亠 PHP JsonWire Protocol Selenium Server Browser Browser PHP JsonWire Protocol Selenium Server
丼仂 仆亠仂弍仂亟亳仄仂 亟仍 亠舒仍亳亰舒亳亳     PHP binding  ? Object model TestSuit JsonWireProtocol
Test Suit  亰舒亠仄 仂仆仂 仆亢仆仂, 仂  于弍舒 ? PHPUnit (PEAR) PHP Simpletests PHPUnit Project PHPUnit 1.0.0
丼仂 仆亠仂弍仂亟亳仄仂 亟仍 亠舒仍亳亰舒亳亳     PHP binding  ? Object model PHPUnit (PEAR) JsonWireProtocol
PHP Object model  仗仂舒仆仂于从舒 亰舒亟舒亳. 仂舒仆仂于从舒 亰舒亟舒亳: a.  舒亰弍仂 JsonWireProtocol; b.  亠舒仍亳亰舒亳 PHP 仂弍亠从仆仂亶 仄仂亟亠仍亳; c.  仆亠亞舒亳 仗仂仍亠仆仆仂亶 仄仂亟亠仍亳   PHPUnit;
Json Wire Protocol  舒亰弍仂 从仂仄舒仆亟   ELEMENT POST /session/:sessionId/element URL Parameters: :sessionId  - ID 亠亳亳 JSON Parameters: using - {string}  于 亟舒仆仆仂仄 从仂仆从亠仆仂仄 仍舒亠 仂 仍仂从舒仂, 弌丐丐亊 仍仂从舒仂舒. value - {string}  亰仆舒亠仆亳亠 仍仂从舒仂舒.
Returns: {ELEMENT:string}  JSON 仆仂, 仍仂从舒仍亳亰ム亳亶 仍亠仄亠仆. Potential Errors: NoSuchElement  - 仍亳 仍亠仄亠仆 仆亠 弍仍 仆舒亶亟亠仆. XPathLookupError  - 仍亳 于 从舒亠于亠 弌丐丐 仍仂从舒仂舒 弍仍 亰舒亟舒仆 仆亠 于亠仆亶 XPath . Json Wire Protocol  舒亰弍仂 从仂仄舒仆亟   ELEMENT
Json Wire Protocol   仗亳从仍舒亟仆仂亶 仗亳仄亠  亳仂亟仆亠 亟舒仆仆亠
Json Wire Protocol   仗亳从仍舒亟仆仂亶 仗亳仄亠  仂仄亳仂于舒仆亳亠 亰舒仗仂舒  S E L E N I U M http_type:  POST url:  http://localhost:4444/wd/hub/session/1232412/element {  " using ":" id ",  " value ":" edit-submit " } Array ( [ using ] =>  id [ value ] =>  edit-submit ) json
HTTP/1.1 200 OK Date: Sun, 05 Feb 2012 22:06:28 GMT Server: Jetty/5.1.x (Linux/2.6.32-38-generic i386 java/1.6.0_20 Content-Length: 138 Content-Type: application/json;charset=UTF-8 {"status":0,"sessionId":"1328478524467","value":{"ELEMENT":"2"}, "class":"org.openqa.selenium.remote.Response","hCode":5604828} Json Wire Protocol   仗亳从仍舒亟仆仂亶 仗亳仄亠  仗仂仍亠仆亳亠  仂于亠舒  S E L E N I U M
Array ( [ header ] => HTTP/1.1 200 OK Date: Sun, 05 Feb 2012 22:06:28 GMT Server: Jetty/5.1.x (Linux/2.6.32-38-generic i386 java/1.6.0_20 Content-Length: 138 Content-Type: application/json;charset=UTF-8 [ body ] => {" status ": 0 ," sessionId ":" 1328478524467 ", " value ":{" ELEMENT ":" 2 "},"class":"org.openqa.selenium.remote.Response", "hCode":5604828} ) json_decode Json Wire Protocol   仗亳从仍舒亟仆仂亶 仗亳仄亠  舒亰弍仂  仂于亠舒
Element  Object ( [ driver:Element:private ] => Driver  Object ( [ session_id:protected ] =>  1328478524467 [ server_url:protected ] =>  http://localhost:4444/wd/hub [ browser:protected ] =>  firefox ) [ element_id:Element:private ] =>  2 [ locator:Element:private ] =>  id=edit-submit ) Json Wire Protocol   仗亳从仍舒亟仆仂亶 仗亳仄亠  舒亰弍仂  仂于亠舒  ??????
Json Wire Protocol  于亠 亳从仍.
亠舒仍亳亰舒亳  PHP  仂弍亠从仆仂亶 仄仂亟亠仍亳
亠舒仍亳亰舒亳  PHP  仂弍亠从仆仂亶 仄仂亟亠仍亳 . 仂仄亳仂于舒仆亳亠  Json  亳亰  ObjectPHP public function  execute( $http_type ,  $relative_url ,  $payload  = null )  { ... $response  = WebDriver:: Curl ( $http_type ,  $full_url ,  $payload ); ... return  $response ; }
亠舒仍亳亰舒亳  PHP  仂弍亠从仆仂亶 仄仂亟亠仍亳 . 舒弍仂舒 c  Element public function  __construct( $driver ,  $element_id ,  $locator ) { $this-> driver  =  $driver ; } private function  execute( $driver ,  $element_id ,  $locator ) { return  $this-> driver ->execute( $http_type ,  $relative_url ,  $payload = null ); } public function  click() { $this->execute(" POST ", " /click "); }
亠舒仍亳亰舒亳  PHP  仂弍亠从仆仂亶 仄仂亟亠仍亳 . TestSuit    PHPUnit  亳仆亠亞舒亳 class  myTest  extends  PHPUnit_Framework_TestCase {  public function  setUp() { } public function  test() { } public function  tearDown() { } }
亠舒仍亳亰舒亳  PHP  仂弍亠从仆仂亶 仄仂亟亠仍亳 . TestSuit    PHPUnit  亳仆亠亞舒亳 class  myTest  extends  PHPUnit_Framework_TestCase   {   protected  $ driver ; public  function setUp() { $this -> driver  = Driver:: InitAtHost (' 4444 ', ' firefox '); }   public function   __call( $name ,  $arguments )   { ... return  call_user_func_array( array ( $this -> driver ,   $name ),   $arguments ); ... } }
亠舒仍亳亰舒亳  PHP  仂弍亠从仆仂亶 仄仂亟亠仍亳 . TestSuit    PHPUnit  亳仆亠亞舒亳,  ASSERT class  Element   { ... public function  assert_string_present( $expected_string ) { $page_text   =   $this ->get_text(); PHPUnit_Framework_Assert:: assertContains ( $expected_string , $page_text , " Failed asserting ... "); } }
亠舒仍亳亰舒亳  PHP  仂弍亠从仆仂亶 仄仂亟亠仍亳 .
亠舒仍亳亰舒亳  PHP  仂弍亠从仆仂亶 仄仂亟亠仍亳 . TestSuit    PHPUnit , 亰舒仗从  弌 <phpunit   stopOnFailure =&quot; false &quot;  colors =&quot; false &quot; > <testsuites> <testsuite name=&quot;change user status&quot;> <file> pixwoo/functionalTestNew.php </file> <file> pixwoo/functionalTestPublic.php </file> <file> pixwoo/functionalTestProfile.php </file>   </testsuite> </testsuites> </phpunit>
亠舒仍亳亰舒亳   JavaScript  亳仆亠从亳亳   find, click, move,  亰舒亠仄 ?
亠舒仍亳亰舒亳   JavaScript  亳仆亠从亳亳   find, click, move,  亰舒亠仄 ? $this ->execute(&quot; POST &quot;, &quot; /session/:sessionId/execute_async &quot;,  array ( &quot; script &quot; =>  $javascript , &quot; args &quot; =>  $arguments , )); $javascript  = &quot;var  callback  = arguments[arguments.length-1];  function  clickElement( handler ){  $( handler ).click(); }  $(document).ready(function(){    clickElement( ... jQuery Selector ... );   callback(amp;quot;doneamp;quot;); });&quot;; 亳仆仂仆仆亶 于亰仂于 JS 亳仄亠仆舒 亠舒仍亳亰舒亳
舒 仂亟亳仆 舒亞 弍仍亳亢亠 从 舒于仂仄舒亳亰舒亳亳. developers testers Version control systems  Git, SVN, ... build servers Jenkins 1 3 2 4 5 6 7 8 9 Bug parser (redmine API)
40 big websites in 2011 www.adyax.com

More Related Content

Alexander manuhin selenium_php_v2.0

  • 1. Selenium and PHP By Alexander Manuhin , QA Manager Adyax 仂于舒 亢亳亰仆 WebDriver 亳 PHP . 仂 舒亰舒弍仂从亳 亠亶仄于仂从舒 亟仂 仂亞舒仆亳亰舒亳亳 仗仂亳亰于仂亟于亠仆仆仂亞仂 仗仂亠舒.
  • 2. 40 big websites in 2011 www.adyax.com
  • 3. PHP+WebDriver 于仂仂亠 亟舒仆亳亠
  • 4. PHP 于 从舒亠于亠 binding 亟仍 WebDriver ?
  • 5. 丼仂 仆亠仂弍仂亟亳仄仂 亟仍 亠舒仍亳亰舒亳亳 PHP binding ? Object model TestSuit Protocol
  • 6. Json Wire Protocol 从舒从 仂 舒弍仂舒亠 ? Json Wire Protocol - JSON 亠亠亰 HTTP 舒仗仂 于亠 PHP JsonWire Protocol Selenium Server Browser Browser PHP JsonWire Protocol Selenium Server
  • 7. 丼仂 仆亠仂弍仂亟亳仄仂 亟仍 亠舒仍亳亰舒亳亳 PHP binding ? Object model TestSuit JsonWireProtocol
  • 8. Test Suit 亰舒亠仄 仂仆仂 仆亢仆仂, 仂 于弍舒 ? PHPUnit (PEAR) PHP Simpletests PHPUnit Project PHPUnit 1.0.0
  • 9. 丼仂 仆亠仂弍仂亟亳仄仂 亟仍 亠舒仍亳亰舒亳亳 PHP binding ? Object model PHPUnit (PEAR) JsonWireProtocol
  • 10. PHP Object model 仗仂舒仆仂于从舒 亰舒亟舒亳. 仂舒仆仂于从舒 亰舒亟舒亳: a. 舒亰弍仂 JsonWireProtocol; b. 亠舒仍亳亰舒亳 PHP 仂弍亠从仆仂亶 仄仂亟亠仍亳; c. 仆亠亞舒亳 仗仂仍亠仆仆仂亶 仄仂亟亠仍亳 PHPUnit;
  • 11. Json Wire Protocol 舒亰弍仂 从仂仄舒仆亟 ELEMENT POST /session/:sessionId/element URL Parameters: :sessionId - ID 亠亳亳 JSON Parameters: using - {string} 于 亟舒仆仆仂仄 从仂仆从亠仆仂仄 仍舒亠 仂 仍仂从舒仂, 弌丐丐亊 仍仂从舒仂舒. value - {string} 亰仆舒亠仆亳亠 仍仂从舒仂舒.
  • 12. Returns: {ELEMENT:string} JSON 仆仂, 仍仂从舒仍亳亰ム亳亶 仍亠仄亠仆. Potential Errors: NoSuchElement - 仍亳 仍亠仄亠仆 仆亠 弍仍 仆舒亶亟亠仆. XPathLookupError - 仍亳 于 从舒亠于亠 弌丐丐 仍仂从舒仂舒 弍仍 亰舒亟舒仆 仆亠 于亠仆亶 XPath . Json Wire Protocol 舒亰弍仂 从仂仄舒仆亟 ELEMENT
  • 13. Json Wire Protocol 仗亳从仍舒亟仆仂亶 仗亳仄亠 亳仂亟仆亠 亟舒仆仆亠
  • 14. Json Wire Protocol 仗亳从仍舒亟仆仂亶 仗亳仄亠 仂仄亳仂于舒仆亳亠 亰舒仗仂舒 S E L E N I U M http_type: POST url: http://localhost:4444/wd/hub/session/1232412/element { &quot; using &quot;:&quot; id &quot;, &quot; value &quot;:&quot; edit-submit &quot; } Array ( [ using ] => id [ value ] => edit-submit ) json
  • 15. HTTP/1.1 200 OK Date: Sun, 05 Feb 2012 22:06:28 GMT Server: Jetty/5.1.x (Linux/2.6.32-38-generic i386 java/1.6.0_20 Content-Length: 138 Content-Type: application/json;charset=UTF-8 {&quot;status&quot;:0,&quot;sessionId&quot;:&quot;1328478524467&quot;,&quot;value&quot;:{&quot;ELEMENT&quot;:&quot;2&quot;}, &quot;class&quot;:&quot;org.openqa.selenium.remote.Response&quot;,&quot;hCode&quot;:5604828} Json Wire Protocol 仗亳从仍舒亟仆仂亶 仗亳仄亠 仗仂仍亠仆亳亠 仂于亠舒 S E L E N I U M
  • 16. Array ( [ header ] => HTTP/1.1 200 OK Date: Sun, 05 Feb 2012 22:06:28 GMT Server: Jetty/5.1.x (Linux/2.6.32-38-generic i386 java/1.6.0_20 Content-Length: 138 Content-Type: application/json;charset=UTF-8 [ body ] => {&quot; status &quot;: 0 ,&quot; sessionId &quot;:&quot; 1328478524467 &quot;, &quot; value &quot;:{&quot; ELEMENT &quot;:&quot; 2 &quot;},&quot;class&quot;:&quot;org.openqa.selenium.remote.Response&quot;, &quot;hCode&quot;:5604828} ) json_decode Json Wire Protocol 仗亳从仍舒亟仆仂亶 仗亳仄亠 舒亰弍仂 仂于亠舒
  • 17. Element Object ( [ driver:Element:private ] => Driver Object ( [ session_id:protected ] => 1328478524467 [ server_url:protected ] => http://localhost:4444/wd/hub [ browser:protected ] => firefox ) [ element_id:Element:private ] => 2 [ locator:Element:private ] => id=edit-submit ) Json Wire Protocol 仗亳从仍舒亟仆仂亶 仗亳仄亠 舒亰弍仂 仂于亠舒 ??????
  • 18. Json Wire Protocol 于亠 亳从仍.
  • 19. 亠舒仍亳亰舒亳 PHP 仂弍亠从仆仂亶 仄仂亟亠仍亳
  • 20. 亠舒仍亳亰舒亳 PHP 仂弍亠从仆仂亶 仄仂亟亠仍亳 . 仂仄亳仂于舒仆亳亠 Json 亳亰 ObjectPHP public function execute( $http_type , $relative_url , $payload = null ) { ... $response = WebDriver:: Curl ( $http_type , $full_url , $payload ); ... return $response ; }
  • 21. 亠舒仍亳亰舒亳 PHP 仂弍亠从仆仂亶 仄仂亟亠仍亳 . 舒弍仂舒 c Element public function __construct( $driver , $element_id , $locator ) { $this-> driver = $driver ; } private function execute( $driver , $element_id , $locator ) { return $this-> driver ->execute( $http_type , $relative_url , $payload = null ); } public function click() { $this->execute(&quot; POST &quot;, &quot; /click &quot;); }
  • 22. 亠舒仍亳亰舒亳 PHP 仂弍亠从仆仂亶 仄仂亟亠仍亳 . TestSuit PHPUnit 亳仆亠亞舒亳 class myTest extends PHPUnit_Framework_TestCase { public function setUp() { } public function test() { } public function tearDown() { } }
  • 23. 亠舒仍亳亰舒亳 PHP 仂弍亠从仆仂亶 仄仂亟亠仍亳 . TestSuit PHPUnit 亳仆亠亞舒亳 class myTest extends PHPUnit_Framework_TestCase { protected $ driver ; public function setUp() { $this -> driver = Driver:: InitAtHost (' 4444 ', ' firefox '); } public function __call( $name , $arguments ) { ... return call_user_func_array( array ( $this -> driver , $name ), $arguments ); ... } }
  • 24. 亠舒仍亳亰舒亳 PHP 仂弍亠从仆仂亶 仄仂亟亠仍亳 . TestSuit PHPUnit 亳仆亠亞舒亳, ASSERT class Element { ... public function assert_string_present( $expected_string ) { $page_text = $this ->get_text(); PHPUnit_Framework_Assert:: assertContains ( $expected_string , $page_text , &quot; Failed asserting ... &quot;); } }
  • 25. 亠舒仍亳亰舒亳 PHP 仂弍亠从仆仂亶 仄仂亟亠仍亳 .
  • 26. 亠舒仍亳亰舒亳 PHP 仂弍亠从仆仂亶 仄仂亟亠仍亳 . TestSuit PHPUnit , 亰舒仗从 弌 <phpunit stopOnFailure =&quot; false &quot; colors =&quot; false &quot; > <testsuites> <testsuite name=&quot;change user status&quot;> <file> pixwoo/functionalTestNew.php </file> <file> pixwoo/functionalTestPublic.php </file> <file> pixwoo/functionalTestProfile.php </file> </testsuite> </testsuites> </phpunit>
  • 27. 亠舒仍亳亰舒亳 JavaScript 亳仆亠从亳亳 find, click, move, 亰舒亠仄 ?
  • 28. 亠舒仍亳亰舒亳 JavaScript 亳仆亠从亳亳 find, click, move, 亰舒亠仄 ? $this ->execute(&quot; POST &quot;, &quot; /session/:sessionId/execute_async &quot;, array ( &quot; script &quot; => $javascript , &quot; args &quot; => $arguments , )); $javascript = &quot;var callback = arguments[arguments.length-1]; function clickElement( handler ){ $( handler ).click(); } $(document).ready(function(){ clickElement( ... jQuery Selector ... ); callback(amp;quot;doneamp;quot;); });&quot;; 亳仆仂仆仆亶 于亰仂于 JS 亳仄亠仆舒 亠舒仍亳亰舒亳
  • 29. 舒 仂亟亳仆 舒亞 弍仍亳亢亠 从 舒于仂仄舒亳亰舒亳亳. developers testers Version control systems Git, SVN, ... build servers Jenkins 1 3 2 4 5 6 7 8 9 Bug parser (redmine API)
  • 30. 40 big websites in 2011 www.adyax.com

Editor's Notes

  • #3: Hi all, thank you for coming. My name is Maxime Topolov. Im CTO and co-founder of Adyax, european leader on Drupal. Ill try to introduce you Drupal.