From APP Android end automation test beginner’s notes, write wrong place we a lot of advice oh

In the previous script development stage, we used PyCharm IDE to run the script. However, after the script development was completed, it would be unreasonable and troublesome to open the IDE every time to run the automatic test. Besides, PyCharm occupies a large memory resource, which affects the execution efficiency. We can run it using CMD or packaged as Bat batch script.

Notepad++ download link: notepad-plus-plus.org/downloads/v…

Start the Appium service

1. Create a Notepad on the desktop, open notepad and fill in the following contents (note to switch to the English input method)

Start a single service
@echo off
appium
pause

Start multiple services
@echo off
appium -p 4725
pause
Copy the code

@echo off: disables echo to make the CLI cleaner

2. Click File → Save as, change the file name suffix to. Bat, save type to All files, code to UTF-8, and click Save

3. The utf-8 format saved using the above method is not the utf-8 we need, so use Notepad++ to open, change the encoding to “utf-8”, save and exit

4. Double-click to start the Appium service

Execute test cases

1. Create a Notepad on the desktop, open notepad and fill in the following contents (note to switch to the English input method)

@echo offCD Go to the directory where the test case resides python Test case file pause For example:@echo off
e:
cd E:\study\Fork\WeiboDemo\Weibo\testcase\
D:\Develop\Python\python.exe -m pytest test_add_weibo.py
pause
Copy the code

The other steps are the same as above

Matters needing attention:

1. Before the command is executed, add the following import sys in the add_weibo_test.py script

import sys
path = "E:\\study\\Fork\\WeiboDemo\\Weibo\\"
sys.path.append(path)
Copy the code

The project runs in IDE in a different path than in CMD. When running in PyCharm, the parent path of PyCharm + our project directory is the run directory by default. When importing packages, we will first look at the package from the pythonPATH environment variable. If your pythonPATH contains a directory that does not have the root of the project directory, you will get an error importing projects that are not in the same directory.

The result is as follows:

Problems:

ModuleNotFoundError: No module named ‘… The command line cannot find the path of the module. You can use the following solution:

import sys
path ="E:\\study\\Fork\\WeiboDemo\\Weibo\\"
sys.path.append(path)
from common.init_two import DesiredCaps
Copy the code

Place the script for path configuration at the top of the file