Selenium4 automated testing framework

Introduction to Selenium

Selenium is currently the most widely used Web UI automated testing framework. Its core function is to conduct automated testing on multiple browsers and supports multiple programming languages. It has been widely used by Google, Baidu, Tencent and other companies.

Development steps

1. Configure the environment variables of the Google driver. If not configured, you need to specify the driver location in the code.

2. Import Java Selenium dependencies into eclipse.

3. Write script code.

Login to the website

WebDriver driver=new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().pageLoadTimeout(300000, TimeUnit.SECONDS);
driver.get("http://192.168.2.169:8090/login");
driver.findElement(By.name("username")).sendKeys("wydong");
driver.findElement(By.name("cipher")).sendKeys("123456");
driver.findElement(By.id("login")).click();

element positioning

1. Positioning by id.

2. Position by name.

3. Positioning through tagName.

4. Position through className.

5. Position through linkText (link all text).

6. Position through partialLinkText (link partial text).

7. Positioning through XPath (relative path).

8. Positioning through cssSelector (recommended).

WebDriver operations

1. Get the page source code.

2. Get the url of the current page.

3. Access the specified url.

4. Close the driver object.

5. Get the handle of the open page.

element wait

1. Hard waiting, thread sleep.

2. Implicit waiting, continuously searching for elements during the timeout period.

3. Display the test and wait until a certain condition is met before continuing to execute.

WebDriver needs to switch scenes

1. Operate the alert pop-up box.

2. Operate the confirm pop-up box.

3. Manipulate elements within iframe.

4. Manipulate the Window element.

other

1. Execute scripts through the JavascriptExcutor object to operate some page elements.

2. Through the Action object, you can imitate some special operations of the mouse, such as right-clicking and dragging.

3. For uploading of non-input boxes, use third-party tools to upload files (such as autoit).

4. How to handle the verification code: manual removal, image recognition or universal verification code (backend verification must be passed).

5. With the help of other professional frameworks, beautiful test reports can be generated.

A full set of practical tutorials for web automated testing: Python+Selenium4 environment construction

Guess you like

Origin blog.csdn.net/ada4656/article/details/135198875