1. Seven ways to locate web elements
The 6 preferred
find_element_by_id (returns an element)
find_element(s)_by_class_name (obtains a list of elements based on the class name)
find_element(s)_by_name (returns a list of elements containing tag objects based on the value of the tag’s name attribute)
find_element(s)_by_link_text ( Get the element list according to the link text)
find_element(s)_by_partial_link_text (get the element list according to the text contained in the link)
find_element(s)_by_tag_name (get the element list according to the tag name)
find_element(s)_by_css_selector get according to the css selector
The two find_element(s)_by_css_selector used as a last resort
(according to the css selector to obtain a list of elements)
find_element(s)_by_xpath (returns a list containing elements)
2. Three ways to locate app elements
by_id
by_class_name
by_xpath
3. adb common command
adb help: adb --help
Start the adb service: adb start-server
Close the adb service: adb kill-server
Get the device number: adb devices
Get the system version: adb shell getprop ro.build.version.release
Send files to the mobile phone: adb push computer file path/file to be sent, path stored on the mobile phone
adb push C:\Users\win\Desktop\xx.png /sdcard
Pull files from the mobile phone: adb pull the path of the mobile phone / pull the file name the path of the stored file on the computer
adb pull /sdcard/xx.png C:\Users\win\Desktop
View mobile phone running log: adb logcat
Enter the phone terminal: adb shell
Install the app to the phone: adb install path/xxx.apk
Uninstall mobile app: adb uninstall app
Get the app startup package name and startup name (⚠The phone needs to open the corresponding app first)
Mac/Linux: adb shell dumpsys window windows | grep mFocusedApp
Run in Windows terminal: adb shell dumpsys window w | findstr mCurrent
Get app startup time: adb shell am start -W package name/.startup name
View device ip address:
adb shell ifconfig wlan0
adb shell netcfg
View device cpu information: adb shell cat /proc/cpuinfo
View device memory information: adb shell cat /proc/meminfo
Light up the screen: adb shell input keyevent 224
To turn off the screen: adb shell input keyevent 223
-
Keyboard operation commonly used functions
send_keys(Keys.BACK_SPACE) delete key (BackSpace)
send_keys(Keys.SPACE) space bar (Space)
send_keys(Keys.TAB) tab key (Tab)
send_keys(Keys.ESCAPE) back key (Esc)
send_keys(Keys.ENTER) Enter key (Enter)
send_keys(Keys.CONTROL,'a') Select all (Ctrl+A)
send_keys(Keys.CONTROL,'c') Copy (Ctrl+C)
send_keys(Keys.CONTROL ,'v') Select all (Ctrl+V)
send_keys(Keys.CONTROL,'x') Copy (Ctrl+X)
4. Common mouse function
context_click() Right click --> This method simulates the effect of right mouse click
double_click () Double-click --> This method simulates double-click double-click effect
drag_and_drop() Drag --> This method simulates double-label drag effect
move_to_element() Hover --> This method simulates mouse hover effect
perform() Execution -- > This method is used to execute all mouse methods above -
selenium principle
-
The whole process is: python --- http request ---> Chromedrive.exe --- js ---> browser
Python sends http requests through the requests library. After receiving the request, the driver will access the corresponding interface, then convert some parameters into JS code, and then execute the browser operation through dom, bom, etc., and finally return the corresponding content to python
6. apppium:
an open source, cross-platform UI automation testing tool that supports test scripts written in
multiple
languages
. Requests are forwarded to bootstrap.jar.
3. The jar receives the appium command and calls the UIAutomator command to implement the operation.
4. The final result is returned to the Appium server by bootstrap.jar.
7. Fixture
1. Must inherit the unittest.TestCase class, setUp, tearDown is a fixture;
2. setUp: generally do initialization work, such as: instantiate browser, browser maximize, implicit wait settings
3. tearDown: general Do the finishing work, such as: log out, close the browser
4. If a test class has multiple test start methods, setUp will be run before each method is executed, and tearDown will be run at the end