Successfully reported this slideshow.
 
Testing Magento with  Selenium IDE <ul><li>Dmitriy Romanov </li></ul><ul><li>Professional Service QA Engineer </li></ul><u...
Contents Why Automate Testing ?  Why Selenium ?  “ Create Simple Product with Related” Example :  <ul><ul><li>Recording ma...
Why Automate Testing ? <ul><ul><li>Fast Execution and Feedback </li></ul></ul><ul><ul><li>Reliable </li></ul></ul><ul><ul>...
Selenium usage example
Why Selenium ?
Why Selenium ?
Why Selenium ?
 
Selenium Advantages <ul><li>Run directly in Browser </li></ul><ul><li>Support AJAX testing  </li></ul><ul><li>Multibrowser...
Input Parameters:  <ul><ul><li>Product Name:  </li></ul></ul><ul><ul><li>Simple Product </li></ul></ul><ul><ul><li>SKU </l...
Для примера построения такого теста возьмем такую часть функционала Админ части, как создание простого (Simple) продукта. ...
 
Finding solid start point: <ul><ul><li>click </li></ul></ul>//ul[@id='nav']/li[3]/ul/li[1]/a/span <ul><ul><li>… </li></ul>...
Using meaningful locators: <ul><ul><li>click </li></ul></ul>//ul[@id='nav']/li[3]/ul/li[1]/a/span click //div[@class=&quot...
Avoid autogenerated IDs: click <ul><ul><li>id_8ad1a1cebaeae9432f842806bb7bf99a </li></ul></ul>с lick <ul><ul><li>id_481d27...
Script parameterization with Variables Recorded script:  select product_type  label= Simple Product click id_481d270db3266...
Script parameterization with Variables Introducing variables:  store <ul><ul><li>Simple Product </li></ul></ul>Name store ...
Script parameterization with Variables Using variables:  type name ${Name} type description ${Name} type short_description...
Improve script readability click //a[@id=' product_info_tabs_group_5 ']/span   type Price 12 select tax_class_id label=Tax...
Using XPath functions: Website selection:  click //a[@id='product_info_tabs_websites']/span   click product_website_44   U...
Using XPath functions: …  d iv[@id='grop_fields']/div[12]/div[1]/big/strong/label
Using XPath functions: <label for=&quot;product_website_44&quot; class=&quot; &quot;>Selenium Website</label>  //div[@id=’...
Using XPath functions:
Using XPath functions: Website selection:  click product_website_44   Updated version:  click //div[@id='product_info_tabs...
Working with AJAX: Category selection:  click //a[@id='product_info_tabs_categories']/span   click ext-gen485   Updated ve...
Причина в том, что сразу после перехода на закладку категорий дерево категорий  еще не отрисовано и нет еще элемента с име...
Working with AJAX:
Working with AJAX. Main Question What’s up, Doc ?
Working with AJAX: Awaiting AJAX Response Solutions: Use  Pause(waitTime) OR Get Answer for the Question: “ What’s changed...
Working with AJAX:
Working with AJAX:
Working with AJAX:
Working with AJAX: Category selection:  click //a[@id='product_info_tabs_categories']/span   click ext-gen485   click //a[...
Dynamical changes: Related products additions: click //a[@id='product_info_tabs_related']/span   type filter_sku ssp-RA cl...
Dynamical changes: Corrected version: click //ul[@id='product_info_tabs']//a[span='Related Products']   type filter_sku ${...
Using User Interface Map Original Selenese: click id_1b1bca379a27ffade3083654c82ac9d9   Magento EE 1.6.x - 1.7.x: ClickAnd...
Using User Interface Map : Dealing With Changed Design: //button[contains(span,'Save’) and contains(span,'Edit’)'] OR //bu...
Using User Interface Map : UI-Map Example for 1.6.x and 1.7.x : var uiMap = new UIMap();   uiMap.addPageset({ name: 'Dashb...
Using UI-Map UI-Map Example for 1. 8 .x : ... locator: &quot;xpath=//button[span='Save And Continue Edit']&quot; ...
Adding UI-Map extension to IDE :
Adding Assertion to Script: assertTextPresent Product was successfully saved.   assertTextPresent Product  has been  succe...
Review and Comment Source: 1 Input parameters 2 Store Simple Product Name 3 Store ssp-01 SKU 4 Store 'Selenium' Website 5 ...
Review and Comment Source: 19 Fill Price Tab 20 click //ul[@id='product_info_tabs']//a[span='Prices']   21 type price 12 2...
Review and Comment Source: 38 type filter_sku ${RelProdSKU1} 39 click //*[@id='related_product_grid']//button[contains(spa...
Script Changes Statistic and Conclusions: Recorder Script Lines Count: 27 Final Script Lines Count: 56 Unchanged Lines: 7
Conclusions: Selenium Best Practices for Magento:  <ul><ul><li>Using meaningful locators </li></ul></ul><ul><ul><li>Using ...
Upcoming SlideShare
Loading in …5
×

Тестирование Magento с использованием Selenium

3,292 views

Published on

Презентация Дмитрия Романова

Published in: Technology, Design
  • Be the first to comment

  • Be the first to like this

Тестирование Magento с использованием Selenium

  1. 2. Testing Magento with Selenium IDE <ul><li>Dmitriy Romanov </li></ul><ul><li>Professional Service QA Engineer </li></ul><ul><li>[email_address] </li></ul>
  2. 3. Contents Why Automate Testing ? Why Selenium ? “ Create Simple Product with Related” Example : <ul><ul><li>Recording macro </li></ul></ul>  <ul><ul><li>Analyzing and fixing script source </li></ul></ul>  <ul><ul><li>Featuring script </li></ul></ul>  Selenium Best Practices for Magento: <ul><ul><li>Using meaningful locators </li></ul></ul><ul><ul><li>Using *waitfor for dynamical changes </li></ul></ul><ul><ul><li>Script parameterization with Variables </li></ul></ul><ul><ul><li>Break out link between TestLogic and </li></ul></ul><ul><ul><li>XPath functions and expressions in Selenium </li></ul></ul><ul><ul><li>How to add Assert* and Verify* </li></ul></ul><ul><ul><li>Working with Non-Visible Page Elements </li></ul></ul><ul><ul><li>Using Comments </li></ul></ul>
  3. 4. Why Automate Testing ? <ul><ul><li>Fast Execution and Feedback </li></ul></ul><ul><ul><li>Reliable </li></ul></ul><ul><ul><li>Repeatable </li></ul></ul><ul><ul><li>Comprehensive </li></ul></ul><ul><ul><li>Reusable parts </li></ul></ul><ul><ul><li>Better Software Quality </li></ul></ul><ul><ul><li>Overall QA Cost Reduction </li></ul></ul>
  4. 5. Selenium usage example
  5. 6. Why Selenium ?
  6. 7. Why Selenium ?
  7. 8. Why Selenium ?
  8. 10. Selenium Advantages <ul><li>Run directly in Browser </li></ul><ul><li>Support AJAX testing </li></ul><ul><li>Multibrowser </li></ul><ul><li>Multiplatform </li></ul><ul><li>Extendable </li></ul><ul><li>Multilanguage </li></ul><ul><li>Free and Open Source </li></ul>
  9. 11. Input Parameters: <ul><ul><li>Product Name: </li></ul></ul><ul><ul><li>Simple Product </li></ul></ul><ul><ul><li>SKU </li></ul></ul><ul><ul><li>sp-01 </li></ul></ul><ul><ul><li>Price </li></ul></ul><ul><ul><li>12 </li></ul></ul><ul><ul><li>WebSite </li></ul></ul><ul><ul><li>Selenium </li></ul></ul><ul><ul><li>Category </li></ul></ul><ul><ul><li>SeL </li></ul></ul><ul><ul><li>Related products SKU1 </li></ul></ul><ul><ul><li>ssp-RA </li></ul></ul><ul><ul><li>Related products SKU2 </li></ul></ul><ul><ul><li>ssp-RB </li></ul></ul>Condition to check: <ul><ul><li>Successful message: </li></ul></ul>“ Product was successfully saved. ”
  10. 12. Для примера построения такого теста возьмем такую часть функционала Админ части, как создание простого (Simple) продукта. В тесте заполним все необходимые поля для отображения на фронте. Из необязательных – добавим два related продукта. Демонстрационное видео создания продукта можно посмотреть отдельно.
  11. 14. Finding solid start point: <ul><ul><li>click </li></ul></ul>//ul[@id='nav']/li[3]/ul/li[1]/a/span <ul><ul><li>… </li></ul></ul>
  12. 15. Using meaningful locators: <ul><ul><li>click </li></ul></ul>//ul[@id='nav']/li[3]/ul/li[1]/a/span click //div[@class=&quot; nav-bar &quot;]//li [a/span=&quot; Manage Products &quot;]/a
  13. 16. Avoid autogenerated IDs: click <ul><ul><li>id_8ad1a1cebaeae9432f842806bb7bf99a </li></ul></ul>с lick <ul><ul><li>id_481d270db32669b7f9f7092eedc00242 </li></ul></ul>clickAndWait <ul><ul><li>//button[span=&quot;Add Product&quot;] </li></ul></ul>clickAndWait <ul><ul><li>//button[span=&quot;Continue&quot;] </li></ul></ul>
  14. 17. Script parameterization with Variables Recorded script: select product_type label= Simple Product click id_481d270db32669b7f9f7092eedc00242   type name Simple Product type description Simple Product type short_description Simple Product type sku ssp-01 type weight 10 select status label=Enabled
  15. 18. Script parameterization with Variables Introducing variables: store <ul><ul><li>Simple Product </li></ul></ul>Name store <ul><ul><li>ssp-01 </li></ul></ul>SKU store <ul><ul><li>Selenium </li></ul></ul>Website store <ul><ul><li>SeL </li></ul></ul>Category store <ul><ul><li>ssp-RA </li></ul></ul>RelProdSKU1 store <ul><ul><li>ssp-RB </li></ul></ul>RelProdSKU2
  16. 19. Script parameterization with Variables Using variables: type name ${Name} type description ${Name} type short_description ${Name} type sku ${SKU } type weight 10 select status label=Enabled
  17. 20. Improve script readability click //a[@id=' product_info_tabs_group_5 ']/span   type Price 12 select tax_class_id label=Taxable Goods click //a[@id= 'product_info_tabs_inventory ']/span   type inventory_qty 1000 select inventory_stock_availability label=In Stock click //ul[@id='product_info_tabs']//a[span='Prices']   type Price 12 select tax_class_id label=Taxable Goods click //ul[@id='product_info_tabs']//a[span='Inventory']   type inventory_qty 1000 select inventory_stock_availability label=In Stock
  18. 21. Using XPath functions: Website selection: click //a[@id='product_info_tabs_websites']/span   click product_website_44   Updated version: click //ul[@id='product_info_tabs']//a[span='Websites’]   click ???  
  19. 22. Using XPath functions: … d iv[@id='grop_fields']/div[12]/div[1]/big/strong/label
  20. 23. Using XPath functions: <label for=&quot;product_website_44&quot; class=&quot; &quot;>Selenium Website</label> //div[@id=’product_info_tabs_websites_content’]//label //div[@id='product_info_tabs_websites_content'] //label[ text ()='Selenium Website'] label[text()=${Website}+' Website'] //div[@id='product_info_tabs_websites_content'] //label[ text ()= concat (${Website},' Website')] //div[@id='product_info_tabs_websites_content'] //label[ contains ( text (),${Website})]
  21. 24. Using XPath functions:
  22. 25. Using XPath functions: Website selection: click product_website_44   Updated version: click //div[@id='product_info_tabs_websites_content'] //label[contains(text(),${Website})]  
  23. 26. Working with AJAX: Category selection: click //a[@id='product_info_tabs_categories']/span   click ext-gen485   Updated version: click //a[@id='product_info_tabs_categories']/span   click //div[@id='product-categories'] //a[contains(span,${Category})]  
  24. 27. Причина в том, что сразу после перехода на закладку категорий дерево категорий еще не отрисовано и нет еще элемента с именем нашей категории. Замена click на clickandwait здесь не поможет, т.к., фактически, страница не перегружается, а заново отрисовывается только ее часть. Так работает AJAX-технология, которая с помощью AJAX запросов/ответов меняет содержимое страницы без полной перезагрузки. Для того, чтобы найти решение, нужно ответить на вопрос: Что поменялось на странице ?
  25. 28. Working with AJAX:
  26. 29. Working with AJAX. Main Question What’s up, Doc ?
  27. 30. Working with AJAX: Awaiting AJAX Response Solutions: Use Pause(waitTime) OR Get Answer for the Question: “ What’s changed on Page ?”
  28. 31. Working with AJAX:
  29. 32. Working with AJAX:
  30. 33. Working with AJAX:
  31. 34. Working with AJAX: Category selection: click //a[@id='product_info_tabs_categories']/span   click ext-gen485   click //a[@id='product_info_tabs_categories']/span   waitForElementNotPresent //div[@id='loading-mask' and contains(@style,'display: none')]   waitForElemenPresent //div[@id='loading-mask' and contains(@style,'display: none')]   Click //div[@id='product-categories']//a[contains(span,${Category})]  
  32. 35. Dynamical changes: Related products additions: click //a[@id='product_info_tabs_related']/span   type filter_sku ssp-RA click id_39e3a2128d47dfd177243389483acede   click //input[@name='' and @value='240']   type filter_sku ssp-RB click id_39e3a2128d47dfd177243389483acede   click //input[@name='' and @value='241']  
  33. 36. Dynamical changes: Corrected version: click //ul[@id='product_info_tabs']//a[span='Related Products']   type filter_sku ${RelProdSKU1} click //*[@id='related_product_grid']//button[contains(span,'Search')]   waitForElementNotPresent //div[@id='loading-mask' and contains(@style,'display: none')]   waitForElemenPresent //div[@id='loading-mask' and contains(@style,'display: none')]   waitForElementPresent //table[@id='related_product_grid_table']//td[contains(text(),${RelProdSKU1})]   click //table[@id='related_product_grid_table']//td[contains(text(),${RelProdSKU1})]   type filter_sku ${RelProdSKU2} click //*[@id='related_product_grid']//button[contains(span,'Search')]   waitForElementPresent //table[@id='related_product_grid_table']//td[contains(text(),${RelProdSKU1})]   с lick //table[@id='related_product_grid_table']//td[contains(text(),${RelProdSKU1})]  
  34. 37. Using User Interface Map Original Selenese: click id_1b1bca379a27ffade3083654c82ac9d9   Magento EE 1.6.x - 1.7.x: ClickAndWait //button[span='Save A nd Continue Edit']   Magento EE 1.8.x: ClickAndWait //button[span='Save a nd Continue Edit']  
  35. 38. Using User Interface Map : Dealing With Changed Design: //button[contains(span,'Save’) and contains(span,'Edit’)'] OR //button[upper-case(span)='SAVE AND CONTINUE EDIT'] OR //button[translate(span,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')='SAVE AND CONTINUE EDIT'] OR Using UI-Map
  36. 39. Using User Interface Map : UI-Map Example for 1.6.x and 1.7.x : var uiMap = new UIMap();   uiMap.addPageset({ name: 'Dashboard', description: 'Main page with operations menu', paths: ['index.php/control/index'] });   uiMap.addElement('Dashboard', { name: 'saveandcontinue_button', description: 'Save and Continue button', locator: &quot;xpath=//button[span='Save And Continue Edit']&quot; });
  37. 40. Using UI-Map UI-Map Example for 1. 8 .x : ... locator: &quot;xpath=//button[span='Save And Continue Edit']&quot; ...
  38. 41. Adding UI-Map extension to IDE :
  39. 42. Adding Assertion to Script: assertTextPresent Product was successfully saved.   assertTextPresent Product has been successfully saved. assertTextPresent ui=Dashboard::product_saved_message()  
  40. 43. Review and Comment Source: 1 Input parameters 2 Store Simple Product Name 3 Store ssp-01 SKU 4 Store 'Selenium' Website 5 Store 'SeL-Category' Category 6 Store ssp-RA RelProdSKU1 7 Store ssp-RB RelProdSKU2 8 Open manage products, click &quot;Add Product&quot; 9 clickAndWait //div[@class=&quot;nav-bar&quot;]//li[a/span=&quot;Manage Products&quot;]/a   10 clickAndWait //button[span=&quot;Add Product&quot;]   11 clickAndWait //button[span=&quot;Continue&quot;]   12 Fill General Tab 13 type name ${Name} 14 type description ${Name} 15 type short_description ${Name} 16 type sku ${SKU} 17 type weight 10 18 Select status label=Enabled
  41. 44. Review and Comment Source: 19 Fill Price Tab 20 click //ul[@id='product_info_tabs']//a[span='Prices']   21 type price 12 22 select tax_class_id label=Taxable Goods 23 Fill Inventory Tab 24 click //ul[@id='product_info_tabs']//a[span='Inventory']   25 type inventory_qty 100 26 select inventory_stock_availability label=In Stock 27 Fill Websites Tab 28 click //ul[@id='product_info_tabs']//a[span='Websites']   29 click //div[@id='product_info_tabs_websites_content']//label[contains(text(),${Website})]   30 Fill Category Tab 31 click //ul[@id='product_info_tabs']//a[span='Categories']   32 waitForElementNotPresent //div[@id='loading-mask' and contains(@style,'display: none')]   33 waitForElementPresent //div[@id='loading-mask' and contains(@style,'display: none')]   34 click //div[@id='product-categories']//a[contains(span,${Category})]   35 Fill Related Products Tab 36 click //ul[@id='product_info_tabs']//a[span='Related Products']   37 waitForElementPresent filter_sku  
  42. 45. Review and Comment Source: 38 type filter_sku ${RelProdSKU1} 39 click //*[@id='related_product_grid']//button[contains(span,'Search')]   40 waitForElementNotPresent //div[@id='loading-mask' and contains(@style,'display: none')]   41 waitForElementPresent //div[@id='loading-mask' and contains(@style,'display: none')]   42 waitForElementPresent //table[@id='related_product_grid_table']//td[contains(text(),${RelProdSKU1})]   43 click //table[@id='related_product_grid_table']//td[contains(text(),${RelProdSKU1})]   44 type filter_sku ${RelProdSKU2} 45 click //*[@id='related_product_grid']//button[contains(span,'Search')]   46 waitForElementNotPresent //div[@id='loading-mask' and contains(@style,'display: none')]   47 waitForElementPresent //div[@id='loading-mask' and contains(@style,'display: none')]   48 waitForElementPresent //table[@id='related_product_grid_table']/tbody/tr/td[contains(text(),${RelProdSKU2})]   49 click //table[@id='related_product_grid_table']/tbody/tr/td[contains(text(),${RelProdSKU2})]   50 Save And Continue 51 click ui=Dashboard::saveandcontinue_button()   52 Product saved assertion 53 assertElementPresent ui=Dashboard::product_saved_message()  
  43. 46. Script Changes Statistic and Conclusions: Recorder Script Lines Count: 27 Final Script Lines Count: 56 Unchanged Lines: 7
  44. 47. Conclusions: Selenium Best Practices for Magento: <ul><ul><li>Using meaningful locators </li></ul></ul><ul><ul><li>Using *waitfor for dynamical changes </li></ul></ul><ul><ul><li>Script parameterization with Variables </li></ul></ul><ul><ul><li>Break out link between TestLogic and Design </li></ul></ul><ul><ul><li>Xpath and JavaScript functions and expressions in Selenium </li></ul></ul><ul><ul><li>When Assert* and Verify* </li></ul></ul><ul><ul><li>Working with Non-Visible Page Elements </li></ul></ul><ul><ul><li>Using Comments </li></ul></ul>

×