Yêu cầu:
- Bạn cần tạo số lượng lớn user hoặc dữ liệu cho 1 công việc cụ thể nào đó (test phân trang/ performance/ search với nhiều dữ liệu/…) và không muốn ngồi nhập cái form register nhàm chán cả trăm lần.
- Bạn có 1 số lượng testcase và muốn chạy bộ testcase đó 10/ 20/… lần để kiểm tra sự ổn định của cả testcase và các chức năng của hệ thống. Hoặc một ngày nào đó sếp nổi hứng yêu cầu em chạy bộ testcase đó trên server https://abc.xyz/ ít nhất 30 lần cho anh, chẳng lẽ ngồi bấm rồi đợi chạy cho đủ số lần.
Flow Control Plugin:
- 1 extension của trình duyệt firefox hỗ trợ cho Selenium IDE làm việc với các câu lệnh vòng lặp
- Chỉ hỗ trợ cho trình duyệt firefox, vì đơn giản nó là extension của thằng firefox
Cài đặt:
- Như một extension bình thường: https://addons.mozilla.org/en-US/firefox/addon/flow-control/
- Sau khi cài đặt và khởi động lại > bật Selenium IDE trong phần command các bạn sẽ thấy suggest 1 số câu lệnh như: gotoIf, while, endWhile,…
Cách sử dụng:
- Before:
- Command: store || Target: 1 || Value: x (Tạo một biến x)
- Command: while || Target: ${x}<=5 (bắt đầu vòng lặp với điều kiện được kiểm tra là x và 5 là số lần muốn lặp lại)
- Command: echo || Target: ${x} (In ra số lần đã chạy – step này có thể bỏ cũng dc)
- After:
- Command: storeEval || Target: storedVars[‘x’] = ${x}+1 (Sau mỗi lần chạy tăng biến x lên 1)
- Command: endWhile (Kết thúc vòng lặp while)
Yêu cầu testcase:
Đăng kí 5 account vào trang live.guru99.com (Xem chi tiết trong bài viết 02: Tạo dữ liệu ngẫu nhiên)
- Step 01 – Truy cập vào trang: http://live.guru99.com/
- Step 02 – Vào trang đăng nhập:
- http://live.guru99.com/index.php/customer/account/
- Click MY ACCOUNT link
- Step 03 – Click CREATE AN ACCOUNT button
- Step 04 – Nhập thông tin hợp lệ vào tất cả các field: First Name/ Last Name/ Email Address/ Password/ Confirm Password (Lưu ý: Tạo random cho dữ liệu tại field Email Address)
- Step 05 – Verify message xuất hiện khi đăng kí thành công: Thank you for registering with Main Website Store.
- Step 06 – Logout khỏi hệ thống
Demo:
- Before (Các bạn thấy nó cũng tương tự như BeforeClass trong TestNG)
- After (Tương tự như AfterClass trong TestNG)
Report: Màu đỏ mình highlight phía dưới là số lần đã chạy
- [info] Playing test case TC_04_CreateAccount
- [info] Executing: |store | 1 | x |
- [info] Executing: |while | ${x}<=3 | |
- [info] Executing: |echo | ${x} | |
- [info] echo: 1
- [info] Executing: |open | / | |
- [info] Executing: |store | javascript{Math.random(). toString(9).substring(2,7)} | random |
- [info] Executing: |clickAndWait | css=div.footer > div.links > ul > li.first > a[title=”My Account”] | |
- [info] Executing: |clickAndWait | css=a.button > span > span | |
- [info] Executing: |type | id=firstname | AUTOMATION |
- [info] Executing: |type | id=lastname | TESTING |
- [info] Executing: |type | id=email_address | automation${random}@gmail.com |
- [info] Executing: |type | id=password | 123123 |
- [info] Executing: |type | id=confirmation | 123123 |
- [info] Executing: |click | id=is_subscribed | |
- [info] Executing: |clickAndWait | css=div.buttons-set > button.button | |
- [info] Executing: |waitForText | css=li > span | Thank you for registering with Main Website Store. |
- [info] Executing: |verifyText | css=li > span | Thank you for registering with Main Website Store. |
- [info] Executing: |click | css=a.skip-link.skip-account > span.label | |
- [info] Executing: |clickAndWait | link=Log Out | |
- [info] Executing: |storeEval | storedVars[‘x’]=${x}+1 | |
- [info] script is: storedVars[‘x’]=1+1
- [info] Executing: |endWhile | | |
- [info] Executing: |while | ${x}<=3 | |
- [info] Executing: |echo | ${x} | |
- [info] echo: 2
- [info] Executing: |open | / | |
- [info] Executing: |store | javascript{Math.random(). toString(9).substring(2,7)} | random |
- [info] Executing: |clickAndWait | css=div.footer > div.links > ul > li.first > a[title=”My Account”] | |
- [info] Executing: |clickAndWait | css=a.button > span > span | |
- [info] Executing: |type | id=firstname | AUTOMATION |
- [info] Executing: |type | id=lastname | TESTING |
- [info] Executing: |type | id=email_address | automation${random}@gmail.com |
- [info] Executing: |type | id=password | 123123 |
- [info] Executing: |type | id=confirmation | 123123 |
- [info] Executing: |click | id=is_subscribed | |
- [info] Executing: |clickAndWait | css=div.buttons-set > button.button | |
- [info] Executing: |waitForText | css=li > span | Thank you for registering with Main Website Store. |
- [info] Executing: |verifyText | css=li > span | Thank you for registering with Main Website Store. |
- [info] Executing: |click | css=a.skip-link.skip-account > span.label | |
- [info] Executing: |clickAndWait | link=Log Out | |
- [info] Executing: |storeEval | storedVars[‘x’]=${x}+1 | |
- [info] script is: storedVars[‘x’]=2+1
- [info] Executing: |endWhile | | |
- [info] Executing: |while | ${x}<=3 | |
- [info] Executing: |echo | ${x} | |
- [info] echo: 3
- [info] Executing: |open | / | |
- [info] Executing: |store | javascript{Math.random(). toString(9).substring(2,7)} | random |
- [info] Executing: |clickAndWait | css=div.footer > div.links > ul > li.first > a[title=”My Account”] | |
- [info] Executing: |clickAndWait | css=a.button > span > span | |
- [info] Executing: |type | id=firstname | AUTOMATION |
- [info] Executing: |type | id=lastname | TESTING |
- [info] Executing: |type | id=email_address | automation${random}@gmail.com |
- [info] Executing: |type | id=password | 123123 |
- [info] Executing: |type | id=confirmation | 123123 |
- [info] Executing: |click | id=is_subscribed | |
- [info] Executing: |clickAndWait | css=div.buttons-set > button.button | |
- [info] Executing: |waitForText | css=li > span | Thank you for registering with Main Website Store. |
- [info] Executing: |verifyText | css=li > span | Thank you for registering with Main Website Store. |
- [info] Executing: |click | css=a.skip-link.skip-account > span.label | |
- [info] Executing: |clickAndWait | link=Log Out | |
- [info] Executing: |storeEval | storedVars[‘x’]=${x}+1 | |
- [info] script is: storedVars[‘x’]=3+1
- [info] Executing: |endWhile | | |
- [info] Executing: |while | ${x}<=3 | |
- [info] Test case passed
Code:
TC_04_CreateAccount <table cellpadding="1" cellspacing="1" border="1"> <thead> <tr> <td rowspan="1" colspan="3">TC_04_CreateAccount</td> </tr> </thead> <tbody> <!--BEFORE--> <tr> <td>store</td> <td>1</td> <td>x</td> </tr> <tr> <td>while</td> <td>${x}<=2</td> <td></td> </tr> <tr> <td>echo</td> <td>${x}</td> <td></td> </tr> <!--================================================================--> <!--Step 01--> <tr> <td>open</td> <td>/</td> <td></td> </tr> <!--Tạo 1 biến là random--> <tr> <td>store</td> <td>javascript{Math.random(). toString(9).substring(2,7)}</td> <td>random</td> </tr> <!--Step 02--> <tr> <td>clickAndWait</td> <td>css=div.footer > div.links > ul > li.first > a[title="My Account"]</td> <td></td> </tr> <!--Step 03--> <tr> <td>clickAndWait</td> <td>css=a.button > span > span</td> <td></td> </tr> <!--Step 04--> <tr> <td>type</td> <td>id=firstname</td> <td>AUTOMATION</td> </tr> <tr> <td>type</td> <td>id=lastname</td> <td>TESTING</td> </tr> <!--Truyền biến random vào field EMAIL--> <tr> <td>type</td> <td>id=email_address</td> <td>automation${random}@gmail.com</td> </tr> <tr> <td>type</td> <td>id=password</td> <td>123123</td> </tr> <tr> <td>type</td> <td>id=confirmation</td> <td>123123</td> </tr> <tr> <td>click</td> <td>id=is_subscribed</td> <td></td> </tr> <tr> <td>clickAndWait</td> <td>css=div.buttons-set > button.button</td> <td></td> </tr> <!--Step 05--> <tr> <td>waitForText</td> <td>css=li > span</td> <td>Thank you for registering with Main Website Store.</td> </tr> <tr> <td>verifyText</td> <td>css=li > span</td> <td>Thank you for registering with Main Website Store.</td> </tr> <tr> <td>click</td> <td>css=a.skip-link.skip-account > span.label</td> <td></td> </tr> <!--Step 06--> <tr> <td>clickAndWait</td> <td>link=Log Out</td> <td></td> </tr> <!--================================================================--> <!--AFTER--> <tr> <td>storeEval</td> <td>storedVars['x']=${x}+1</td> <td></td> </tr> <tr> <td>endWhile</td> <td></td> <td></td> </tr> </tbody> </table>
There was an unexpected error. Msg: Error: non-matching while/endWhile found
Url: chrome://flowcontrol/content/extensions/goto-sel-ide.js?1525939076889, line: 63, column: 19
Selenium.prototype.initialiseLabels@chrome://flowcontrol/content/extensions/goto-sel-ide.js?1525939076889:63:19
Selenium.prototype.reset@chrome://flowcontrol/content/extensions/goto-sel-ide.js?1525939076889:7:5
.start@chrome://selenium-ide/content/selenium-runner.js:191:5
start@chrome://selenium-ide/content/selenium-runner.js:418:3
Debugger.prototype.start@chrome://selenium-ide/content/debugger.js:154:3
Editor.prototype.playCurrentTestCase@chrome://selenium-ide/content/editor.js:925:3
Editor.controller.doCommand@chrome://selenium-ide/content/editor.js:387:9
goDoCommand@chrome://global/content/globalOverlay.js:100:7
oncommand@chrome://selenium-ide/content/selenium-ide.xul:1:1
anh ơi cho em hỏi sao e chạy theo [info] echo: 1
firefox của em chạy ko được testcase này ạ, cứ báo lỗi này ko anh
LikeLike