[Introduction to automated testing] Automated testing of Firefox with Airtest - Selenium (0 basics can also be learned)

1 Introduction

This article will introduce in detail how to use AirtestIDE to drive Firefox tests, and how to drive Firefox without AirtestIDE (VScode as an example). After reading this article, zero-based beginners can also learn Firefox browser automation testing! ! !

2. How to use AirtestIDE to drive Firefox browser

For web automation testing, AirtestIDE currently supports chrome browser and Firefox. Today we will focus on how to use AirtestIDE to drive Firefox browser.

1) Basic knowledge

AirtestIDE has a built-in python environment, and the Airtest-Selenium library is installed in the environment, which is based on Selenium packaging. GeckoDriver is a driver used in conjunction with the Firefox browser. To install GeckoDriver, you need to pay attention to the compatibility of the two versions. Please check  https://github.com/mozilla/geckodriver/releases  . Detailed steps refer to the following:

2) Download GeckoDriver (note that the version corresponding to the operating system is selected)

3) Unzip to get geckodriver.exe

Unzip the file you just downloaded to get geckodriver.exe.

4) Set geckodriver.exe as a system environment variable

Put geckodriver.exe in a certain directory of your computer, and then set system environment variables for it:

现在我也找了很多测试的朋友,做了一个分享技术的交流群,共享了很多我们收集的技术文档和视频教程。
如果你不想再体验自学时找不到资源,没人解答问题,坚持几天便放弃的感受
可以加入我们一起交流。而且还有很多在自动化,性能,安全,测试开发等等方面有一定建树的技术大牛
分享他们的经验,还会分享很多直播讲座和技术沙龙
可以免费学习!划重点!开源的!!!
qq群号:110685036

5) Drive Firefox in AirtestIDE to do simple automated testing

GIF cover

# -*- encoding=utf8 -*-

from airtest.core.api import *
from airtest.cli.parser import cli_setup
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from airtest_selenium.proxy import WebFirefox
import time

#创建Chrome浏览器驱动实例
browser = WebFirefox(firefox_binary=r"C:\Program Files\MozillaFirefox\firefox.exe")

# 访问网页
browser.get('https://www.baidu.com')

#打印页面标题
print(browser.title)

#休眠3秒
time.sleep(3)

#关闭浏览器
browser.quit()

① Release Notes

【AirtestIDE】1.2.15:https://airtest.netease.com/changelog.html【python】3.6.5:AirtestIDE内置【Firefox】113.0.2 (64 位)【geckodriver】0.33.0(win64):https://github.com/mozilla/geckodriver/releases/tag/v0.33.0

② Start error reporting

When running the above demo, I encountered an error similar to this at the beginning:

selenium.common.exceptions.WebDriverException: Message: Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line

After querying, it is found that the executable file of Firefox cannot be found, so when creating WebFirefox, the path of the executable file of firefox.exe is passed as a parameter WebFirefox, and then it can run normally.

3. How to drive Firefox without AirtestIDE (vscode as an example)

1) Preconditions: install VScode, configure python environment

2) Python configuration airtest, airtest-selenium

You can refer to: How to deploy the local python environment using the following commands:

pip install airtest

pip install airtest-selenium

The pip version of the editor is too old, and pip needs to be updated, using the command: python -m pip install --upgrade pip

3) Test whether the environment is configured successfully in the cmd console

4) Test the script demo to solve the error

① No module named pynput

If the library is missing  pynputpip installjust install it directly.

② TypeError: init() got an unexpected keyword argument......

Ctrl + left mouse button to proxy.pythe file;  the parameter to argument 'timeout'delete if an error occurs timeout=timeout; the parameter to argument 'firefox_options'delete if an error occurs firefox_options=firefox_options.

5) Drive Firefox from AirtestIDE

4. Summary

This is the end of today's tutorial on driving Firefox. If you want to see more about Airtest, you can leave us a comment/message.

The following are supporting learning materials. For friends who do [software testing], it should be the most comprehensive and complete preparation warehouse. This warehouse also accompanied me through the most difficult journey. I hope it can help you too!

Software testing interview applet

The software test question bank maxed out by millions of people! ! ! Who is who knows! ! ! The most comprehensive quiz mini program on the whole network, you can use your mobile phone to do the quizzes, on the subway or on the bus, roll it up!

The following interview question sections are covered:

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

Information acquisition method:

Guess you like

Origin blog.csdn.net/m0_60166861/article/details/132040399