Web automation testing key data records

The role of recording key data

1. Behavior log records

  • Log configuration
  • Script log level
    • debug log information
    • info records key information, such as assertions, etc.
def test_record_data(self):
        self.driver.get("https://www.sogou.com")
        key_word = "华测"
        self.driver.find_element(By.CSS_SELECTOR, "#query").send_keys(key_word)
        logger.debug(f"搜索的内容为{key_word}")
        # 点击搜索
        self.driver.find_element(By.CSS_SELECTOR, "#stb").click()
        # 搜索结果
        search_res = self.driver.find_element(By.CSS_SELECTOR, "em")
        logger.info(f"搜索结果为{search_res.text}")
        assert search_res.text == key_word

2. Step screenshot recording

  • driver.save_screenshot (path + file name)
  • Record key pages
    • assertion page
    • Important business scenario page
    • error-prone pages

 

3. Page source record

  • Use the page_source attribute to get the page source code
  • During the debugging process, if there is an error that the element cannot be found, you can save the page_source debugging code at that time.
  • Combined with open(file) to write the web page source code into a file
with open(fliename,"w",encoding="utf-8") as f:
    f.write(self.driver.page_source)

Problem: No such element error occurs.
Solution: Print the web page code before the page error is reported to facilitate problem location and analysis.

Finally: The following is the supporting learning materials, which should be the most comprehensive and complete preparation warehouse for friends who do [software testing]. This warehouse has also accompanied me through the most difficult journey. I hope it can also help you! [100% free to receive without any tricks]

Software testing interview applet

A software test question bank that has been used by millions of people! ! ! Who is who knows! ! ! The most comprehensive interview test mini program on the Internet, you can use your mobile phone to answer questions, take the subway, bus, and roll it up!

Covers the following interview question sections:

1. Basic theory of software testing, 2. web, app, interface function testing, 3. network, 4. database, 5. linux

6. Web, app, interface automation, 7. Performance testing, 8. Programming basics, 9. HR interview questions, 10. Open test questions, 11. Security testing, 12. Computer basics

  How to obtain the full set of information: Click on the small card below to get it yourself

Guess you like

Origin blog.csdn.net/weixin_57794111/article/details/133638570