Sample Analysis in Sencha application UI Testing

Source: Internet
Author: User

I translated an article "Sencha application UI test" yesterday, which contains a sample application, but I did not elaborate on how to write it, this article describes this example.
First, let's take a look at the qatest startup page index.html ui-tests \ app directory ):[Html]View plaincopy

  1. <! DOCTYPE html>
  2. <Html>
  3. <Head>
  4. <! -- Ext JS -->
  5. <Link rel = "stylesheet" type = "text/css" href = "http://cdn.sencha.io/ext-4.1.0-gpl/resources/css/ext-all.css">
  6. <Script type = "text/javascript" src = ".../resources/extjs-4.1.0/ext-all-debug.js"> </script>
  7. <! -- Siesta -->
  8. <Link rel = "stylesheet" type = "text/css" href = ".../resources/siesta-1.1.5-lite/resources/css/siesta-all.css">
  9. <Script type = "text/javascript" src = ".../resources/siesta-1.1.5-lite/siesta-all.js"> </script>
  10. <! -- The test harness -->
  11. <Script type = "text/javascript" src = "index. js"> </script>
  12. </Head>
  13. <Body>
  14. </Body>
  15. </Html>

The Code contains references from Ext JS and Siesta. The actual execution file should be index. js. The Code is as follows: [Javascript]View plaincopy
  1. Var Harness = Siesta. Harness. Browser;
  2. Harness. configure ({
  3. Title: 'sencha UI Test Demo-Application Tests ',
  4. HostPageUrl: '.../../index.html ',
  5. Preload :[
  6. '../.../Resources/sinon-1.5.2.js ',
  7. 'Api _ stub. js'
  8. ]
  9. });
  10. Harness. start (
  11. {
  12. Group: 'Basic application layout ',
  13. Items :[
  14. {
  15. Title: 'test tabs for data in grids ',
  16. Url: 'tests/01_tabs.js'
  17. },
  18. {
  19. Title: 'test double-click functionality ',
  20. Url: 'tests/02_rsvp00000000js'
  21. }
  22. ]
  23. }
  24. );

The code first points Harness to Siesta. Harness. Browser to facilitate code writing. Configure for startup ). In the configuration, the title should be the title. The next is the hostPageUrl, which can be known as the application startup page based on the address. Preload is the file to be preloaded. sinon is used to organize data. api_stub.js uses this to generate the returned data. The next step is to execute the start method and start running the test. Two items are set in the test. One is to call 01_tabs.js, the other is to call 02_rsvp;.js, and the two items on the left of the graph are displayed on the page. Next, let's take a look at the file 02_rsvp0000.js. The typical code is as follows: [Javascript]View plaincopy
  1. StartTest (function (t ){
  2. Var tabPanel, upcomingEvents, pasteven ts;
  3. T. chain (
  4. {WaitFor: 500}, // Allow time for the application to render
  5. // Also try to give the Meetup.com API time to return... see note below
  6. Function (next ){
  7. // Set references after rendering
  8. TabPanel = Ext. ComponentQuery. query ('tabpanel ') [0];
  9. UpcomingEvents = tabPanel. items. getAt (0 );
  10. Pasteven Ts = tabPanel. items. getAt (1 );
  11. Next ();
  12. },
  13. Function (next ){
  14. T. diag ('test that the upcoming event grid displays an RSVP popup when a row is double-clicked .');
  15. T. doubleClick (upcomingEvents. el. down ('. x-grid-row'). dom, function (){
  16. Var win = Ext. ComponentQuery. query ('rsvpwindow') [0];
  17. T. is (win. isHidden (), false, 'rsvpwindow shocould be visible .');
  18. Win. close ();
  19. Next ();
  20. });
  21. },
  22. Function (next ){
  23. T. diag ('Switch tabs ');
  24. // Click on the past events tab
  25. T. click (tabPanel. el. query ('. x-tab') [1], next );
  26. },
  27. {WaitFor: 500}, // allow animation to complete
  28. Function (next ){
  29. T. diag ('test that the past event grid displays an RSVP popup when a row is double-clicked .');
  30. T. doubleClick (pasteven ts. el. down ('. x-grid-row'). dom, function (){
  31. Var win = Ext. ComponentQuery. query ('rsvpwindow') [0];
  32. T. is (win. isHidden (), false, 'rsvpwindow shocould be visible .');
  33. Win. close ();
  34. Next ();
  35. });
  36. }
  37. );
  38. });

I read two files in a fixed format, both of which start with "StartTest (function (t) {", and then write the test function in JSON format in t. chain. First, obtain the component to be tested. The doubleClick In the second function indicates that it is used to test the double-click operation of the Grid row. The key here is that the first parameter needs to find the HTML element to be tested. If the pop-up window shows correct, close can be executed correctly. The third function is switched to the test tab. The key is to know how to find elements. The 4th functions are also used to test the double-click operation of the Grid row.
In general, writing test code will not be too difficult. The key point is to master some methods of Siesta and to correctly obtain the elements of the components to be tested.

This article from the "yellow light bridge blog", please be sure to keep this source http://dqhuang.blog.51cto.com/2522725/1117986

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.