Write the directory title here
- 1. What do you do if the needs of page elements change frequently?
- 2. Did you encounter any problems during the automation process? For example
- 3. How to deal with the alert pop-up window
- 4. How to handle multiple windows in selenium?
- 5. Have you ever encountered elements in a Frame when searching for them? How do you handle the positioning of elements in a Frame?
- 6. How to deal with drop-down menus?
- 7. What is the difference between quit and close in closing the browser?
- 8. How to upload files (to be added)?
- 9. How to implement mouse hover, keyboard events and drag and drop actions?
- 10. In selenium automated testing, what types of tests do you usually complete?
- 11. Have automated tests ever falsely reported bugs? What should I do if a false positive occurs (*)?
- 12. What problems did you encounter during the automated testing process and how did you solve them (*)?
- 13. How to improve the execution speed of selenium scripts
- 14. How to automate testing of functions containing verification codes
- 15. What are the usage scenarios of automated testing (important)?
- 16. Please describe the automated testing process (important)?
- 17. What is the difference between web and app automation (important)?
- 18. The difference between http and https (important)
- 19. How to ensure the success rate of operating elements in Selenium? In other words, how can I ensure that the element I click on is clickable?
- 20. Commonly used functions for mouse operations (to be added)
1. What do you do if the needs of page elements change frequently?
Using the po mode, business logic and test logic are separated. When a page changes frequently, you only need to maintain the page, including element positioning expressions and encapsulated business methods; there is no need to modify the test logic; frequent changes in the page are the pain points of automated testing
. We cannot change the requirements. Currently, using the PO model is the most effective solution.
2. Did you encounter any problems during the automation process? For example
a. The page changes frequently and the script needs to be modified.
b. The script is unstable and often fails to run.
c. Improving efficiency will affect stability.
3. How to deal with the alert pop-up window
First switch to the pop-up window: alert=driver.switch_to.alert
Confirm: alert.accept()
Cancel: alert.dismiss()
Get the text in the pop-up window: alert.getText()
Enter the content in the pop-up window:alert.sendkeys()
4. How to handle multiple windows in selenium?
Test with Baidu browser:
a. Obtain the search page window of Baidu browser
search_window=driver.current_window_handle
b. Click the "hao123" label to jump to the hao123 page.
driver.find_element_by_xpath('//a[text()="hao123"]').click()
time.sleep(2)
c. Get all window handles
all_handles=driver.window_handles
d. Switch to hao123 page
for handle in all_handles:
if handle!=search_window:
driver.switch_to.window(handle)
driver.find_element_by_xpath('//a[text()="网易"]').click()
e. If you switch to the search page again
driver.switch_to.window(search_window)
5. Have you ever encountered elements in a Frame when searching for them? How do you handle the positioning of elements in a Frame?
Switch to frame
def switch_frame(frame_el):
driver.switch_to.frame(frame_el)
el=driver.find_element_by_xpath('//input[@id="kw"]')
el.input('kobe')
frame_el=driver.find_element_by_xpath('//iframe[@name="baidu"]')
switch_frame(frame_el)
Return to home page
driver.switch_to.default_content()
6. How to deal with drop-down menus?
a. Search by text text
def select(el):
s=Select(el) #初始化Select对象
s.select_by_visible_text('kobe')
el=driver.find_element_by_xpath('//select[@id="faver"]')
b. Search by value
def select(el):
s=Select(el)
s.select_by_value('double')
el=driver.find_element_by_xpath('//select[@id="faver"]')
7. What is the difference between quit and close in closing the browser?
driver.quit(): Close the entire browser
driver.close(): Close the current page
quit is generally used before ending the test, and close is used to close a certain page during the execution of the use case.
8. How to upload files (to be added)?
The first method: send_keys
a. Find the entrance to upload the file
b. Get the expression of the entry element (file_el)
c. Upload the file
file_el.send_keys(r'c:\666.doc')
Second method: pywinauto
def upload_file(self):
# 点击上传文件按钮
self.browser.find_element_by_xpath('//span[contains(text(),"点击上传")]').click()
# 使用pywinauto来选择文件
app = pywinauto.Desktop()
# 选择文件上传的窗口
dlg = app['打开']
# 选择文件地址输入框,点击
dlg['Toolbar3'].click()
# 键盘输入上传文件的路径
send_keys(r'C:\Users\Lenovo')
# 键盘输入回车键,打开该路径
send_keys('{VK_RETURN}')
# 选中文件名输入框,输入文件名
dlg['文件名(&N):Edit'].type_keys('1.jpg')
# 点击打开
time.sleep(2)
#dlg['打开(&O)'].click()
dlg['打开(&O)'].double_click()
time.sleep(2)
return self
9. How to implement mouse hover, keyboard events and drag and drop actions?
a. Mouseover
1、初始化一个action_chains对象
action=ActionChains(driver)
2、找到要悬浮的元素,
setting_el=driver.find_element_by_xpath(‘//span[@id=“s-usersetting-top”]’) -----> 设置
3、调用鼠标操作的函数,传入move_to_element()函数中
action.move_to_element(setting_el)
4、要让动作生效的话,必须加上perform
action.move_to_element(setting_el).perform()
5、再定位到高级设置标签
top_setting_el=driver.find_element_by_xpath(‘//a[text()=“高级搜索”]’)
top_setting_el.click()
b. Drag action
def drag_and_drop(el1,el2)
action=ActionChains(driver)
action.drag_and_drop(el1,el2)
action.proform()
drag_and_drop(el1,el2)
c. Double-click
def double_click(el)
action=ActionChains(driver)
action.double_click(el)
action.perform()
double_click(el)
10. In selenium automated testing, what types of tests do you usually complete?
Project stability
regression testing
monitoring
11. Have automated tests ever falsely reported bugs? What should I do if a false positive occurs (*)?
There have been false positives. Sometimes the automated test report shows that a bug has been found, but manual testing is actually used to confirm that the bug does not exist.
The reasons for false positives are generally:
a. The element positioning is unstable (no waiting or the waiting time is set too short; the elements change dynamically, and element expressions need to be optimized), b. The
stability of the script needs to be improved as much as possible (use independent Test environment, use cases and use cases should be independent of each other, and try not to be too coupled); c
. The development updated the page but the test was not updated and maintained in time!
d. Network problems (the page loads too slowly)
12. What problems did you encounter during the automated testing process and how did you solve them (*)?
Efficiency and stability
require major changes, and the code needs to be maintained.
False positives occur, reason: Question 11
13. How to improve the execution speed of selenium scripts
a. Do not use forced waiting
b. Minimize unnecessary operations
c. Reduce unnecessary io operations
d. Try to use an independent test environment to prevent others from modifying the environment configuration
e. Try not to associate use cases with use cases to reduce the coupling of use cases f .
Use relative
expressions of Stuck and stopped
14. How to automate testing of functions containing verification codes
Universal code
development is closed
15. What are the usage scenarios of automated testing (important)?
a. The demand is stable and will not change frequently.
b. The development and testing cycle is long and regression testing needs to be performed frequently.
c. Scenarios where the same test needs to be run repeatedly on multiple platforms.
d. Some test items cannot be implemented through manual testing, or the manual cost is too high.
e. The development of the software under test is relatively standardized, which can ensure the testability of the system.
f. Online monitoring
16. Please describe the automated testing process (important)?
a. Write automated test plan
b. Design automated test cases
c. Write automated test framework
d. Script debugging
e. Execute test cases, unattended testing
f. Post-script maintenance (add test cases, develop updated versions)
17. What is the difference between web and app automation (important)?
a. Startup difference.
A mobile phone can only test
the web side of one apk package at the same time. Due to multiple processes, a computer can open multiple browsers for testing.
b. Installation difference.
App side: You need to check whether the software is installed before you can test
the web side . : No installation required, just enter the url in the browser to test.
c. Page element operations
d. Use different automated testing frameworks
selenium
appium
18. The difference between http and https (important)
a. HTTP is a hypertext transfer protocol, and information is transmitted in plain text , while HTTPS is a secure SSL encrypted transmission protocol .
b. HTTP and HTTPS use completely different connection methods and use different ports. The former is 80 and the latter is 443.
c. HTTP connection is very simple and stateless. The HTTPS protocol is a network protocol built from the SSL+HTTP protocol that can perform encrypted transmission and identity authentication. It is more secure than the HTTP protocol. (Stateless means that the sending, transmission and reception of data packets are independent of each other. Connectionless means that neither communicating party maintains any information about the other party for a long time.)
19. How to ensure the success rate of operating elements in Selenium? In other words, how can I ensure that the element I click on is clickable?
a. Add invisible waiting and explicit waiting to the script.
b. Use forced waiting when necessary.
c. Use try method to position id, name, clas, x path, css selector in different ways. If the first method fails, you can automatically try the second one. Kind of
d. Need to be in the specified frame and window.
20. Commonly used functions for mouse operations (to be added)
context_click()
Right-click --> This method simulates the double-click effect of a right-click mouse
double_click()
--> This method simulates the dragging effect of a double-click double-click
drag_and_drop()
--> This method simulates the hover effect of a double-click drag
move_to_element()
--> This method simulates
perform()
the execution of a mouse-over effect- -> This method is used to execute all the above mouse methods