Best way to take screenshots of tests in Selenium 2?

后端 未结 13 2163
别跟我提以往
别跟我提以往 2020-11-28 04:29

I need a way to take screenshots of my functional tests. Right now I\'m using Selenium 2 with C# bindings. I pretty much want to take a screenshot at the end of the test to

13条回答
  •  半阙折子戏
    2020-11-28 04:53

    Best way to take screenshot and store in the file location in a generic way in python :

    def screenShots(self):
            fileName= NewFile + "." + str(round(time.time() * 1000)) + ".png"
            screenshotDirectory = "../screenshot/"  #Move to that directory where you want ot store the screenshot
            relativeFileName = screenshotDirectory + fileName
            currentDirectory = os.path.dirname(__file__)
            destinationFile = os.path.join(currentDirectory,relativeFileName)
            destinationDirectory = os.path.join(currentDirectory,screenshotDirectory)
    
            try:
                if not os.path.exists(destinationDirectory):
                    os.makedirs(destinationDirectory)
                self.driver.save_screenshot(destinationFile)
    
                self.log.info("Screenshot saved to directory" + destinationFile)
    
            except:
                self.log.error("Exception Occured")
                print_stack()
    

提交回复
热议问题