Selenium + Java build a complete framework

A, WebDriver framework for the development of actual combat

1, frame of mind

(1) What is the framework?

  • Framework can be customized application developer application skeleton

(2) Why write frame?

  • Improve the maintainability of the script
  • Improve the speed of writing scripts
  • Improve script readability

(3) some elements of the framework?

  • driver management, waiting management, common packaging methods, the LOG commonly used type of packaging, data, and so fail to run heavy

2, preparation - pre-step framework to build

  • New projects by IDEA Maven project's name TestAutomation2019
  • Selenium and TestNG introduced corresponding jar package
  • In the project root folder to create a new driver, placed driver
  • Create a new package: com.autoframework

3, Driver Management

  • New driver package at com.autoframework
  • In the new class driver package SeleniumDriver
  • Packaging driver
  • Code examples demonstrate
  • test
package com.lixx.drivers;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class SeleniumDriver1 {
    public static WebDriver driver;
    public static WebDriver initialDriver(String browser){
        //获取当前工程根目录
        String path = System.getProperty("user.dir");
        if (browser.equals("chrome")){
            System.setProperty("webdriver.chrome.driver", path + "/driver/chromedriver.exe");
            driver = new ChromeDriver();
        }else if (browser.equals("ie")){
            System.setProperty("webdriver.ie.driver", path + "/driver/IEDriverServer.exe");
            driver = new InternetExplorerDriver();
        }else if (browser.equals("firefox")){
            driver = new FirefoxDriver();
        }else if (browser.equals("edge")) { 
            System.setProperty ( "webdriver.edge.driver", path + "/driver/MicrosoftWebDriver.exe" ); 
            Driver = new new EdgeDriver (); 
        } the else { 
            System.out.println ( "Enter your browser name in error, please confirm "! ); 
        } 
        return Driver; 
    } 
}

4, the method waits element package

  • New package element at com.autoframework
  • Under the new element package WebElementUtils class and inherited class SeleniumDriver
  • And a second package findElement method findElements
  • Code examples demonstrate
  • test

 

Guess you like

Origin www.cnblogs.com/xinxin1994/p/11332539.html