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

User Operations: 10 Ways to Motivate Super Members

In order to create more opportunities for brands ...

How to correctly place information flow ads?

Many people think that optimizer is a creative po...

As high temperatures approach, be alert to these 8 summer diseases!

On June 15, the Central Meteorological Observator...

Samsung expected to recover with new Galaxy phones

April 3 news, according to foreign media reports,...

Marketing promotion: Is your marketing plan effective?

How to put a good idea into practice? Are there a...

What does pua mean? So what is the difference between a pua man and a scumbag?

What does pua mean and what is the difference bet...