Python automated test selenium specifies the screenshot file name method

This article mainly introduces the method of specifying screenshot file names for Python automated testing selenium. Selenium supports the automation of web browsers. It provides a set of test functions to support web automated testing. The following is based on Python to implement the method of specifying screenshot file names. What is needed Friends, you can refer to it

Table of contents
  • Foreword:

  • 1. Time and date formatting symbols in Python

  • 2. Usage steps

    • 1. Import the time module and webdriver class

    • 2. Actual code operation

  • Summarize:

Foreword:

Selenium supports the automation of web browsers and provides a set of test functions to support automated web testing. The function is very flexible and can complete functions such as interface element positioning, window jumping, and result comparison. Supports multiple browsers, multiple programming languages ​​(Java, C#, Python, Ruby, PHP, etc.), multiple operating systems (Windows, Linux, IOS, Android, etc.), open source and free.

It mainly consists of three tools: WebDriver, IDE, and Grid.

Selenium architecture:

Complete the Selenium script writing on the client and send the script to the Selenium server. The Selenium server uses the browser driver to interact with the browser.

Selenium core components:

  • WebDriver uses the API provided by the browser to control the browser, just like the user is operating the browser, which is not intrusive.

  • IDE is a Chrome and Firefox extension that can record user operations in the browser.

  • Grid is used in Selenium distribution and you can run test cases on multiple browsers and operating systems.

Method introduction:

  • time.strftime() can be used to obtain the current time, format the time into a string, etc.

  • WebDriver provides the screenshot method get_screenshot_as_file() to capture the current page.

  • get_screenshot_as_file() is generally used to throw exceptions on automated test pages and save test information.

1. Time and date formatting symbols in Python

  • %y two-digit year representation (00-99)

  • %Y represents the four-digit year (000-9999)

  • %m month (01-12)

  • %d day of the month (0-31)

  • %H hour in 24-hour format (0-23)

  • %I hour in 12-hour format (0-12)

  • %M minutes (0-59)

  • %S seconds (00-59)

2. Usage steps

1. Import the time module and webdriver class

code show as below:

import timefrom selenium import webdriver

2. Actual code operation

picture

Summarize:

This concludes this article on the method of specifying screenshot file names for Python automated testing of selenium.

Finally: The complete software testing video tutorial below has been compiled and uploaded. Friends who need it can get it by themselves [guaranteed 100% free]

Software Testing Interview Document

We must study to find a high-paying job. The following interview questions are the latest interview materials from first-tier Internet companies such as Alibaba, Tencent, Byte, etc., and some Byte bosses have given authoritative answers. After finishing this set I believe everyone can find a satisfactory job based on the interview information.

Guess you like

Origin blog.csdn.net/wx17343624830/article/details/133033098