This article is participating in Python Theme Month. See the link for details

This series of columns is a spin-off from snowballing Python, automated testing. I hope the students who need it can enjoy it, and the style of this column will be fun.

What are automated tests and

Testing, is to test developers to come out of the software bugs. Automated testing, is the use of tools or scripts, to achieve no manual or very little manual testing can be completed, to put it simply, automatic testing with tools, testers staring.

Now that automated testing is here, there must be benefits to automation.

  • Automated testing is efficient, and everything is automated for efficiency reasons
  • Do trivial tasks once, the tester is comfortable, work more energy, more time to fish
  • Automated tests, because not human operation, so every time will be the same, there will be no difference between the first and the second operation.

You see, there are a lot of benefits to using automated tests.

Automated testing is not to be sneezed at; it takes a lot to fully automate. Companies have to pay if they want to use it.

First, the technical requirements of the tester must be improved, the original requirements of the mouse can be, and now to write code, second, automatic testing belongs to the test has not been put into the cost of human time, third, project changes, automatic testing scripts must change

Automated testing has become more and more popular in recent years, with tools and frameworks such as Selenium (which we’ll study soon), UFT, and Ruby Watir. Don’t read the last two. We’re not involved.

Selenium

Writing here, the general question is, why do you choose Selenium when there are so many automated testing tools?

It’s because I use it so much at work.

If you want to know something else, go to the search engine (Baidu) to search, a lot of kudos.

From the eraser’s point of view, there are many automation testers who happen to learn Python, who happen to use Selenium, and who happen to work for companies that use Selenium. After all, the more they learn, the more they can prove that they made the right choice.

Selenium IDE installation and use

Starting out with Automated testing, let’s get started with Selenium IDE, which is very easy to get started with and graphical (with the click of a mouse). But that’s not to say it’s easy. When you actually use it, you’ll find it’s a hassle.

To find the official website:

www.selenium.dev/, the download address is in the middle of the page.

Results for a long time, found that the need for Google browser, but also need to visit Google store, domestic is certainly not to achieve.

There’s no way to switch to Firefox.

After installing Firefox, open this address in Firefox. Note that firefox opens: addons.mozilla.org/en-US/firef… Click Add to Firefox.

The above images appear in sequence, and the small image above is finished.

Using the Selenium IDE

After clicking on the image, the following window appears and you are on the road to automated testing.

Choose to create a new project and translate the other content for those whose English is not good.

Write the name of the project freely, but follow a principle, software development can use English alphabet, try not to use Chinese, after all, Chinese profound, not foreigners can understand.

If you need the official tutorials that can open www.seleniumhq.org/selenium-id… , to learn, but for novices, there is no great need to play.

Project created, will enter a new interface, the first look at this interface, must be a face meng. Don’t worry, this is an ordinary software, you can skillfully use QQ, will be able to skillfully operate it.

Since it is learning software operation, it must have the courage to click each button, the most complex software eraser contact is Word in OFFICE, that software, really exciting.

Learn a concept first. The idea behind Selenium automation is to manually record a series of actions and then have the software simulate those actions.

Recording script

Start by recording a script that looks like this; The first step, open Baidu; Step two, click the 123 hyperlink.

Click the record button on the right to record your actions.

The second step is to enter baidu’s url in the pop-up window.

Note that baidu has been opened in the pop-up page, the bottom right content shows that you are recording your operation.

After clicking on the hao123 hyperlink in the upper left corner, open a new page of Hao123 in a new TAB, then close the browser.

At this point, Selenium IDE related operations have been recorded, and you need to manually close the script recording.

Click the button to save (file can be stored anywhere, or Ctrl+S to save)

After recording, you can perform it again. Repeat what you just did.

There are two startup ICONS, one is to execute all scripts, one is to execute the current script, click start, you can see the log below, if you can’t see it, drag the window.

Learn here can be aimed at the technical point in the analysis.

In the figure above, Command, Target, Value, and Description are displayed.

  • Command means Command, and a Command is something we do, like open a web page, click a button.
  • Target stands for Target, which is to find an element in a web page.
  • “Value” is a Value, but I’ll use it later. It’s not mandatory.

Expanding the case

After opening the page, retrieve the title of the page, store it in a variable my_title, and then print that variable.

In the figure above, there are two red boxes: Store title, store title, store title, and Value, store title, store title, store title, store title, store title, store title, store title, store title, store title, store title

${my_title} can be used to print out variable data in the echo command. Note that the print is placed before the close command, otherwise an error will be reported.

You can view the corresponding information in logs.

Note that Selenium IDE is in a waiting state and needs to be stopped manually when running as shown in the following figure.

Implement baidu

Open Baidu in addition to click on the link, but also need to achieve the content of keyword retrieval. You can perform the following operations.

After implementing this set of Settings, a common step is to export to Python code.

Once exported, the code can improve the scripting efficiency of the engineer, after all, some of the steps are already done by recording the script.

Recording a script and testing it is rare in real automated testing because it is not as easy as you might think, so most of the time, we write code.

Write in the back

In this tutorial, you will learn about Selenium in Python and learn about automated testing. Selenium IDE may be used at any time in the later learning process, so it is necessary to learn about it.