Last week's article has taught you how to build your own mock proxy, so today we will look at how this tool is applied to the project~!
Introduction Background
Because the return cost of online money in the mall is high, and it focuses on business, so it needs front-end automation support. Under this premise, I started to try automation in the front section. During the trial, I encountered the problem of case failure caused by the change of the mall order, so I introduced the concept of MockSever. For other students who are similar to this problem, this solution is feasible.
Specific use
Automated directory structure
The previous article has introduced the basic directory of MockServer. Place the corresponding files in the automation project:
All files under the data directory in MockServer ->UI automation data directory
MockServer directory in MockServer ->UI automation src directory
The utils directory in MockServer ->UI Automation src directory
After the above operations are completed, most of the work of applying MockServer is completed. The remaining work is to run the proxy for debugging. The debugging between the two is simple, except for some small episodes. Listen to me.
Problem summary
Problems of parallel work
MockServer is actually a tool that runs independently of automation. In other words, the proxy should be started before UI automation, which means that the two tools should be started in parallel.
Solution (I)
Use the Python multiprocess module to start multiple processes. Create two processes and one process is responsible for the start of a tool. The imagination is full and realistic. When installing, Pycharm reports an error:
There is no solution for the time being. If you know the reason, you can leave a message and learn from each other.
The solution ended in failure.
Solution II
Through sharing in the group, we learned that Python OS library can directly call python files to start, which is a lifesaving straw. We began to try to use the OS library:
dir = os.path.dirname(os.getcwd()) + "\\Mall_UIAutomator\\src\\mockServer"
filename = os.path.join(dir, "mock_init.py" )
os.system( "python %s" %filename)
Unable to wait to click the Run button, the proxy can still run, but this is a resident service, and the following automation code is blocked, which does not achieve the expected effect:
It has been in the monitoring state and failed
Solution (II) Improvement
After a struggle, I searched for information on the Internet and communicated with God. Finally, I improved Scheme II:
dir = os.path.dirname(os.getcwd()) + "\\Mall_UIAutomator\\src\\mockServer"
filename = os.path.join(dir, "mock_init.py" )
os.system( "start /b python %s" %filename)
After careful comparison, students can find that "start/b" check has been added to the improved code. This is to let the program run in the background under cmd. It's amazing. Interested partners can also leave messages. Do you want to check it out.
Conclusion
All articles about mockSever have been shared. Let's review:
Mock Server, A Sharp Tool for Testing 》
《 Let's build MockSever together 》
Well, that's all for today's sharing. If you want to know something that you don't have time to know, please leave a message. Give it to us, and you can wait for the harvest.