Using macaca for mobile hybrid automation testing (Part 4)

Using macaca for mobile hybrid automation testing (Part 4)

Now it is time to test the webview in native. For example, I want to test a component for selecting a city:

The main idea is to simulate a series of user operations and then see whether the test results are consistent with expectations.

First, check the corresponding DOM node through the console, obtain the corresponding DOM element through the API provided by macaca, and then trigger user operations.

The following is still done in the REPL environment:

  1. driver
  2. .webview()
  3. .elementByCssSelector( '.location-city .input-tips' )
  4. .tap() //First, call up the city selection component, as shown in the figure below①
  5. .sleep(500)
  6. .elementByCssSelector( '.province-list .list-item:nth-child(3)' )
  7. .tap() //Click the third element of the province, see the figure below②
  8. .sleep(500)
  9. .elementByCssSelector( '.city-list .list-item:nth-child(4)' )
  10. .tap() //Click on the fourth element of the city, see Figure ③ below
  11. .sleep(500)
  12. .elementByCssSelector( '.area-list .list-item:nth-child(6)' )
  13. .tap() //Click the sixth element in the area, see Figure ④ below
  14. .sleep(500)
  15. .elementByCssSelector( '.location-city .input-tips' )
  16. .text()
  17. . then ( function (value) { //You can see the selected city content output in the console, see Figure ⑤ below
  18. console.log(value);
  19. });

Figure 1:

Figure 2:

[[174582]]

Figure 3:

Figure 4:

Figure ⑤:

Figure 6:

[[174583]]

You can see that the current function is executed as we expected.

Now let me test another situation:

If you select a province and region but not a city, a pop-up window will appear.

  1. driver
  2. .webview()
  3. .elementByCssSelector( '.location-city .input-tips' )
  4. .tap() //Re-awaken the city selection component, see the figure below
  5. .sleep(500)
  6. .elementByCssSelector( '.province-list .list-item:nth-child(2)' )
  7. .tap() //Reselect the province
  8. .sleep(500)
  9. .elementByCssSelector( '.area-list .list-item:nth-child(3)' )
  10. .tap() //Reselect area
  11. //At this time, a pop-up window will appear, see the figure below

Figure 7:

Figure ⑧:

At this time, the function is also running as expected.

Of course, you also need to add assertion-related content to the test script, which is also relatively easy.

I also encountered many problems when writing the webview test script. For example, native restricted the input[type="file"] component that calls native to upload files for security reasons. Some sliding operations were difficult to test, etc. Take your time.

<<:  Using macaca for mobile hybrid automation testing (Part 3)

>>:  Better UI update routine

Recommend

How do internet celebrities monetize their traffic?

There are many ways for internet celebrities to m...

1/2.4 inch phase focus depth analysis Sony IMX230

Sony's Exmor RS series products are no strang...

Teach you how to write hit copy with zero basic knowledge!

My sharing this time is mainly divided into 2 par...

A formula explains: Why do the powerful ones become small brands?

In recent years, you must have noticed these chan...

Tuzki of the succulent world: I don’t want to, ... grow up!

The aquamarine is definitely one of the most popu...

Swift version of infinite loop carousel

Source code introduction: ***Circular carousel GL...

Is it my hair that I'm losing? No, it's probably diamonds!

“A diamond is forever.” Diamonds are highly sough...

Those cute but ferocious "little" animals

Those cute but ferocious "little" anima...

3500 words in-depth analysis: community operation monetization

Community marketing is suitable for products with...