Capture screenshot of failed test cases

后端 未结 1 1131
太阳男子
太阳男子 2021-01-24 17:42

How can I capture a screenshot of the failed test cases in Selenium + Python? I am able to get screenshots of the page but is facing difficulty in capturing screenshots of faile

相关标签:
1条回答
  • 2021-01-24 18:13

    You can do like:

    def test_2new(self):
    
        driver = self.driver 
        driver.get("google.com")
        driver.set_page_load_timeout(10)
        driver.find_element_by_name("q").send_keys("Automation")  
        driver.find_element_by_name("btnK").click()
    
        try:
    
            self.assertTrue("something.com" in self.driver.current_url) 
            print("Google Search!")
    
        except AssertionError:
    
            driver.save_screenshot(r"C:\Users\ANCP2\sample.png")
    

    Hope it helps you!

    0 讨论(0)
提交回复
热议问题