1. 程式人生 > >Java&Selenium自動化測試實現頁面元素、頁面物件及測試程式碼分離

Java&Selenium自動化測試實現頁面元素、頁面物件及測試程式碼分離

一、摘要

本篇博文將介紹自動化測試實現頁面元素、頁面物件及測試程式碼分離在自動化框架中的實現

二、解析頁面元素定位資訊

首先,將頁面元素與實際的程式碼分離,首先我們將頁面元素定位資訊和定位表示式儲存在屬性檔案中,例如我們PaaS平臺提供Mysql服務的頁面,在工程中新建一個名為MysqlService.properties的檔案,檔案中儲存內容類似如下:

[MySQL資料庫服務]
[MySQL資料庫服務-列表]
paas.mysql.refreshbutton=xpath>//*[@id='app']/section/section/main/div[2]/div/div[5]/button
paas.mysql.createnewinstance=xpath>//*[@id='app']/section/section/main/div[2]/div/div[4]/button
paas.mysql.searchinstancenameinput=xpath>//*[@id="app"]/section/section/main/div[2]/div/div[1]/label[1]/div/input
paas.mysql.searchinstancenamebutton=xpath>//*[@id='app']/section/section/main/div[2]/div/div[1]/label[2]/button
paas.mysql.searchspacename=xpath>//*[@id='app']/section/section/main/div[2]/div/div[3]/label[2]/div/div[1]/input
paas.mysql.operation=xpath>//*[@id='app']/section/section/main/section/div[1]/div[3]/table/tbody/tr[1]/td[6]/div/div/span
paas.mysql.operationrestart=xpath>/html/body/ul/li[1]
paas.mysql.operationrelease=xpath>/html/body/ul/li[2]
paas.mysql.operationmanage=xpath>/html/body/ul/li[3]
paas.mysql.operationlog=xpath>/html/body/ul/li[4]
paas.mysql.operationmonitor=xpath>/html/body/ul/li[5]
paas.mysql.confirmrestart=xpath>/html/body/div[1]/div/div[3]/button[2]
paas.mysql.cancelrestart=xpath>/html/body/div[1]/div/div[3]/button[1]
paas.mysql.releaseconfirmbutton=xpath>/html/body/div[1]/div/div[3]/button[2]
paas.mysql.releasecancelbutton=xpath>/html/body/div[1]/div/div[3]/button[1]

[MySQL資料庫服務-建立]
paas.newinstance.instancename=xpath>//*[@id='app']/section/section/main/div[3]/div/div[2]/main/form/div[2]/div/div[1]/input
paas.newinstance.description=xpath>//*[@id='app']/section/section/main/div[3]/div/div[2]/main/form/div[10]/div/div/textarea
paas.newinstance.standard5.6=xpath>//*[@id='app']/section/section/main/div[3]/div/div[2]/main/form/div[4]/div/div/label[1]/span
paas.newinstance.standard5.7=xpath>//*[@id='app']/section/section/main/div[3]/div/div[2]/main/form/div[4]/div/div/label[2]/span
paas.newinstance.instancestandard=xpath>//*[@id='app']/section/section/main/div[3]/div/div[2]/main/form/div[5]/div/div/div[1]/input
paas.newinstance.1c1gb=xpath>/html/body/div[2]/div[1]/div[1]/ul/li[1]
paas.newinstance.1c2gb=xpath>/html/body/div[2]/div[1]/div[1]/ul/li[2]
paas.newinstance.2c8gb=xpath>/html/body/div[2]/div[1]/div[1]/ul/li[3]

三、解析定位元素屬性檔案

滿足selenium的8中定位方式

/*
 * @FileName GetElementUtil: this util is use for getting page element
 * @author davieyang
 * @create 2018-08-21 16:37
 */
package util;
import org.openqa.selenium.By;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

public
class GetElementUtil { private Properties properties; /** * 用於讀取儲存頁面元素的屬性檔案 * @param propFile 屬性檔案的絕對路徑,應定義為常量 */ public GetElementUtil(String propFile){ properties = new Properties(); try{ FileInputStream in = new FileInputStream(propFile); properties.load(in); in.close(); }
catch (IOException e){ System.out.println("讀取物件檔案出錯"); e.printStackTrace(); } } /** * @param elementName 儲存在屬性檔案中的元素名稱"pass.spacemanagement.releasebutton" * @return 根據傳入的頁面元素名獲取元素,返回元素定位 * @throws Exception "輸入的locator Type 未在程式中定義:" + locatorType */ public By getLocator(String elementName) throws Exception{ //根據變數ElementNameInproFile,從屬性配置檔案中讀取對應的配置物件 String locator = properties.getProperty(elementName); //將配置物件中的定位型別存到locatorType變數,將定位表示式的值存到locatorValue變數 String locatorType = locator.split(">")[0]; String locatorValue = locator.split(">")[1]; /** * 配置檔案均預設為ISO-8859-1編碼儲存,使用getBytes方法可以將字串編碼轉換為UTF-8 * 以此來解決讀取中文為亂碼的問題 */ locatorValue = new String(locatorValue.getBytes("ISO-8859-1"), "UTF-8"); //輸出locatorType變數值和locatorValue變數值,驗證是否賦值正確 System.out.println("獲取的定位型別:" + locatorType + "\t獲取的定位表示式" + locatorValue); //根據locatorType的變數值內容判斷返回何種定位方式的By物件 if(locatorType.toLowerCase().equals("id")) return By.id(locatorValue); else if(locatorType.toLowerCase().equals("name")) return By.name(locatorValue); else if(locatorType.toLowerCase().equals("classname")||(locatorType.toLowerCase().equals("class"))) return By.className(locatorValue); else if(locatorType.toLowerCase().equals("tagname")||(locatorType.toLowerCase().equals("tag"))) return By.tagName(locatorValue); else if(locatorType.toLowerCase().equals("linktext")||(locatorType.toLowerCase().equals("link"))) return By.linkText(locatorValue); else if(locatorType.toLowerCase().equals("partiallinktext")) return By.partialLinkText(locatorValue); else if(locatorType.toLowerCase().equals("cssselector")||(locatorType.toLowerCase().equals("css"))) return By.cssSelector(locatorValue); else if(locatorType.toLowerCase().equals("xpath")) return By.xpath(locatorValue); else throw new Exception("輸入的locator Type 未在程式中定義:" + locatorType); } }

四、將頁面元素封裝成物件

/*
 * @FileName StoreManagement: 封裝Mysql頁面物件
 * @outhor davieyang
 * @create 2018-08-08 11:12
 */
package pageobject.resourcemanagement;
import util.GetElementUtil;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import static constants.Constants.MysqlService_Property;
import static util.JavaScriptToDo.highLightElement;

public class MySQLService {
    private static WebElement element = null;
    /**指定頁面元素定位表示式配置檔案的絕對路徑
     *
     */
    private static GetElementUtil getElementUtil = new GetElementUtil(MysqlService_Property);
    private WebDriver driver;
    public MySQLService(WebDriver driver){
        this.driver = driver;
    }

    /**返回MySQL資料庫服務頁面“重新整理”按鈕的頁面元素物件
     *
     * @param driver 瀏覽器驅動
     * @return
     * @throws Exception 獲取定位資訊失敗
     */
    public static WebElement refresh_Button(WebDriver driver) throws Exception{
        //呼叫GetElementUtil中的getLocator方法獲取配置檔案中關於使用者名稱的定位方式和定位表示式
        element = driver.findElement(getElementUtil.getLocator("paas.mysql.refreshbutton"));
        highLightElement(driver, element);
        return element;
    }

    /**返回MySQL資料庫服務頁面“建立例項”按鈕的頁面元素物件
     *
     * @param driver 瀏覽器驅動
     * @return
     * @throws Exception 獲取定位資訊失敗
     */
    public static WebElement create_New_Instance_Button(WebDriver driver) throws Exception{
        //呼叫GetElementUtil中的getLocator方法獲取配置檔案中關於使用者名稱的定位方式和定位表示式
        element = driver.findElement(getElementUtil.getLocator("paas.mysql.createnewinstance"));
        highLightElement(driver, element);
        return element;
    }

    /**
     *
     * @param driver
     * @return
     * @throws Exception
     */
    public static WebElement search_Instance_Name_Input(WebDriver driver) throws Exception{
        //呼叫GetElementUtil中的getLocator方法獲取配置檔案中關於使用者名稱的定位方式和定位表示式
        element = driver.findElement(getElementUtil.getLocator("paas.mysql.searchinstancenameinput"));
        highLightElement(driver, element);
        return element;
    }
    /**返回MySQL資料庫服務頁面MySQL名稱檢索控制元件的頁面元素物件
     *
     * @param driver 瀏覽器驅動
     * @return
     * @throws Exception 獲取定位資訊失敗
     */
    public static WebElement search_Instance_Name_Button(WebDriver driver) throws Exception{
        //呼叫GetElementUtil中的getLocator方法獲取配置檔案中關於使用者名稱的定位方式和定位表示式
        element = driver.findElement(getElementUtil.getLocator("paas.mysql.searchinstancenamebutton"));
        highLightElement(driver, element);
        return element;
    }

    /**返回MySQL資料庫服務頁面執行空間檢索控制元件頁面元素物件
     *
     * @param driver 瀏覽器驅動
     * @return
     * @throws Exception 獲取定位資訊失敗
     */
    public static WebElement search_Space_Name(WebDriver driver) throws Exception{
        //呼叫GetElementUtil中的getLocator方法獲取配置檔案中關於使用者名稱的定位方式和定位表示式
        element = driver.findElement(getElementUtil.getLocator("paas.mysql.searchspacename"));
        highLightElement(driver, element);
        return element;
    }

    /**返回MySQL資料庫服務頁面操作列“。。。”按鈕的頁面元素物件
     *
     * @param driver 瀏覽器驅動
     * @return
     * @throws Exception 獲取定位資訊失敗
     */
    public static WebElement operation_Button(WebDriver driver) throws Exception{
        //呼叫GetElementUtil中的getLocator方法獲取配置檔案中關於使用者名稱的定位方式和定位表示式
        element = driver.findElement(getElementUtil.getLocator("paas.mysql.operation"));
        highLightElement(driver, element);
        return element;
    }

    /**返回MySQL資料庫服務頁面操作列“。。。”裡下拉列表裡的“重啟”按鈕的頁面元素物件
     *
     * @param driver 瀏覽器驅動
     * @return
     * @throws Exception 獲取定位資訊失敗
     */
    public static WebElement operation_Restart_Button(WebDriver driver) throws Exception{
        //呼叫GetElementUtil中的getLocator方法獲取配置檔案中關於使用者名稱的定位方式和定位表示式
        element = driver.findElement(getElementUtil.getLocator("paas.mysql.operationrestart"));
        highLightElement(driver, element);
        return element;
    }

    /**
     *
     * @param driver 瀏覽器驅動
     * @return 返回確認按鈕
     * @throws Exception 獲取定位資訊失敗
     */
    public static WebElement restart_Confirm_Button(WebDriver driver) throws Exception{
        //呼叫GetElementUtil中的getLocator方法獲取配置檔案中關於使用者名稱的定位方式和定位表示式
        element = driver.findElement(getElementUtil.getLocator("paas.mysql.confirmrestart"));
        highLightElement(driver, element);
        return element;
    }

    /**
     *
     * @param driver 瀏覽器驅動
     * @return 返回取消按鈕
     * @throws Exception 定位資訊失敗
     */
    public static WebElement restart_Cancel_Button(WebDriver driver) throws Exception{
        //呼叫GetElementUtil中的getLocator方法獲取配置檔案中關於使用者名稱的定位方式和定位表示式
        element = driver.findElement(getElementUtil.getLocator("paas.mysql.cancelrestart"));
        highLightElement(driver, element);
        return element;
    }


    /**返回MySQL資料庫服務頁面操作列“。。。”裡下拉列表裡的“釋放”按鈕的頁面元素物件
     *
     * @param driver 瀏覽器驅動
     * @return
     * @throws Exception 獲取定位資訊失敗
     */
    public static WebElement operation_Release_Button(WebDriver driver) throws Exception{
        //呼叫GetElementUtil中的getLocator方法獲取配置檔案中關於使用者名稱的定位方式和定位表示式
        element = driver.findElement(getElementUtil.getLocator("paas.mysql.operationrelease"));
        highLightElement(driver, element);
        return element;
    }
    public static WebElement release_Confirm_Button(WebDriver driver) throws Exception{
        //呼叫GetElementUtil中的getLocator方法獲取配置檔案中關於使用者名稱的定位方式和定位表示式
        element = driver.findElement(getElementUtil.getLocator("paas.mysql.releaseconfirmbutton"));
        highLightElement(driver, element);
        return element;
    }
    public static WebElement release_Cancel_button(WebDriver driver) throws Exception{
        //呼叫GetElementUtil中的getLocator方法獲取配置檔案中關於使用者名稱的定位方式和定位表示式
        element = driver.findElement(getElementUtil.getLocator("paas.mysql.releasecancelbutton"));
        highLightElement(driver, element);
        return element;
    }

    /**返回MySQL資料庫服務頁面操作列“。。。”裡下拉列表裡的“管理”按鈕的頁面元素物件
     * 
     * @param driver 瀏覽器驅動
     * @return
     * @throws Exception 獲取定位資訊失敗
     */
    public static WebElement operation_Manage_Button(WebDriver driver) throws Exception{
        //呼叫GetElementUtil中的getLocator方法獲取配置檔案中關於使用者名稱的定位方式和定位表示式
        element = driver.findElement(getElementUtil.getLocator("paas.mysql.operationmanage"));
        highLightElement(driver, element);
        return element;
    }
    /**返回MySQL資料庫服務頁面操作列“。。。”裡下拉列表裡的“管理”按鈕的頁面元素物件
     *
     * @param driver 瀏覽器驅動
     * @return
     * @throws Exception 獲取定位資訊失敗
     */
    public static WebElement database_Link_Tab(WebDriver driver) throws Exception{
        //呼叫GetElementUtil中的getLocator方法獲取配置檔案中關於使用者名稱的定位方式和定位表示式
        element = driver.findElement(getElementUtil.getLocator("paas.detailed.databaselink"));
        highLightElement(driver, element);
        return element;
    }

    /**返回MySQL資料庫服務頁面操作列“。。。”裡下拉列表裡的“日誌”按鈕的頁面元素物件
     * 
     * @param driver 瀏覽器驅動
     * @return
     * @throws Exception 獲取定位資訊失敗
     */
    public static WebElement operation_Log_Button(WebDriver driver) throws Exception{
        //呼叫GetElementUtil中的getLocator方法獲取配置檔案中關於使用者名稱的定位方式和定位表示式
        element = driver.findElement(getElementUtil.getLocator("paas.mysql.operationlog"));
        highLightElement(driver, element);
        return element;
    }

    /**返回MySQL資料庫服務頁面操作列“。。。”裡下拉列表裡的“監控”按鈕的頁面元素物件
     * 
     * @param driver 瀏覽器驅動
     * @return
     * @throws Exception 獲取定位資訊失敗
     */
    public static WebElement operation_Monitor_Button(WebDriver driver) throws Exception{
        //呼叫GetElementUtil中的getLocator方法獲取配置檔案中關於使用者名稱的定位方式和定位表示式
        element = driver.findElement(getElementUtil.getLocator("paas.mysql.operationmonitor"));
        highLightElement(driver, element);
        return element;
    }

    /**
     * 
     * @param driver 瀏覽器驅動
     * @return
     * @throws Exception 獲取定位資訊失敗
     */
    public static WebElement instance_Name_in_Create_Instance_Dialog(WebDriver driver) throws Exception{
        //呼叫GetElementUtil中的getLocator方法獲取配置檔案中關於使用者名稱的定位方式和定位表示式
        element = driver.findElement(getElementUtil.getLocator("paas.newinstance.instancename"));
        highLightElement(driver, element);
        return element;
    }

    /**
     * 
     * @param driver 瀏覽器驅動
     * @return
     * @throws Exception 獲取定位資訊失敗
     */
    public static WebElement description_in_Create_Instance_Dialog(WebDriver driver) throws Exception{
        //呼叫GetElementUtil中的getLocator方法獲取配置檔案中關於使用者名稱的定位方式和定位表示式
        element = driver.findElement(getElementUtil.getLocator("paas.newinstance.description"));
        highLightElement(driver, element);
        return element;
    }

    /**
     * 
     * @param driver 瀏覽器驅動
     * @return
     * @throws Exception 獲取定位資訊失敗
     */
    public static WebElement standard5_6in_Create_Instance_Dialog(WebDriver driver) throws Exception{
        //呼叫GetElementUtil中的getLocator方法獲取配置檔案中關於使用者名稱的定位方式和定位表示式
        element = driver.findElement(getElementUtil.getLocator("paas.newinstance.standard5.6"));
        highLightElement(driver, element);
        return element;
    }

    /**
     * 
     * @param driver 瀏覽器驅動
     * @return
     * @throws Exception 獲取定位資訊失敗
     */
    public static WebElement standard5_7_in_Create_Instance_Dialog(WebDriver driver) throws Exception{
        //呼叫GetElementUtil中的getLocator方法獲取配置檔案中關於使用者名稱的定位方式和定位表示式
        element = driver.findElement(getElementUtil.getLocator("paas.newinstance.standard5.7"));
        highLightElement(driver, element);
        return element;
    }

    /**
     * 
     * @param driver 瀏覽器驅動
     * @return
     * @throws Exception 獲取定位資訊失敗
     */
    public static WebElement storage_Space_in_Create_Instance_Dialog(WebDriver driver) throws Exception{
        //呼叫GetElementUtil中的getLocator方法獲取配置檔案中關於使用者名稱的定位方式和定位表示式
        element = driver.findElement(getElementUtil.getLocator("paas.newinstance.storespace"));
        highLightElement(driver, element);
        return element;
    }
    /**
     * 
     * @param driver 瀏覽器驅動
     * @return
     * @throws Exception 獲取定位資訊失敗
     */
    public static WebElement running_Space_in_Create_Instance_Dialog(WebDriver driver) throws Exception{
        //呼叫GetElementUtil中的getLocator方法獲取配置檔案中關於使用者名稱的定位方式和定位表示式
        element = driver.findElement(getElementUtil.getLocator("paas.newinstance.runtimespace"));
        highLightElement(driver, element);
        return element;
    }

    /**
     * 
     * @param driver 瀏覽器驅動
     * @return
     * @throws Exception 獲取定位資訊失敗
     */
    public static WebElement outsideaccess_Checkbox_in_Create_Instance_Dialog(WebDriver driver) throws Exception{
        //呼叫GetElementUtil中的getLocator方法獲取配置檔案中關於使用者名稱的定位方式和定位表示式
        element = driver.findElement(getElementUtil.getLocator("paas.newinstance.outsideaccess"));
        highLightElement(driver, element);
        return element;
    }

    /**
     * 
     * @param driver 瀏覽器驅動
     * @return
     * @throws Exception 獲取定位資訊失敗
     */
    public static WebElement password_in_Create_Instance_Dialog(WebDriver driver) throws Exception{
        //呼叫GetElementUtil中的getLocator方法獲取配置檔案中關於使用者名稱的定位方式和定位表示式
        element = driver.findElement(getElementUtil.getLocator("paas.newinstance.password"));
        highLightElement(driver, element);
        return element;
    }

    /**
     * 
     * @param driver 瀏覽器驅動
     * @return
     * @throws Exception 獲取定位資訊失敗
     */
    public static WebElement repassword_in_Create_Instance_Dialog(WebDriver driver) throws Exception{
        //呼叫GetElementUtil中的getLocator方法獲取配置檔案中關於使用者名稱的定位方式和定位表示式
        element = driver.findElement(getElementUtil.getLocator("paas.newinstance.repassword"));
        highLightElement(driver, element);
        return element;
    }

    /**
     *
     * @param driver 瀏覽器驅動
     * @return
     * @throws Exception 獲取定位資訊失敗
     */
    public static WebElement cancel_Button_in_Create_Instance_Dialog(WebDriver driver) throws Exception{
        //呼叫GetElementUtil中的getLocator方法獲取配置檔案中關於使用者名稱的定位方式和定位表示式
        element = driver.findElement(getElementUtil.getLocator("paas.newinstance.cancelbutton"));
        highLightElement(driver, element);
        return element;
    }

    /**
     *
     * @param driver 瀏覽器驅動
     * @return
     * @throws Exception 獲取定位資訊失敗
     */
    public static WebElement submit_Button_in_Create_Instance_Dialog(WebDriver driver) throws Exception{
        //呼叫GetElementUtil中的getLocator方法獲取配置檔案中關於使用者名稱的定位方式和定位表示式
        element = driver.findElement(getElementUtil.getLocator("paas.newinstance.surebutton"));
        highLightElement(driver, element);
        return element;
    }

    /**
     * 
     * @param driver 瀏覽器驅動
     * @return instance standard in create instance dialog
     * @throws Exception 獲取定位資訊失敗
     */
    public static WebElement instance_Standard_in_Create_Instance_Dialog(WebDriver driver)throws Exception{
        element = driver.findElement(getElementUtil.getLocator("paas.newinstance.instancestandard"));
        highLightElement(driver, element);
        return element;
    }

    /**
     * 
     * @param driver 瀏覽器驅動
     * @return 返回建立Mysql視窗的例項規格下拉選單的一核一GB
     * @throws Exception 獲取定位資訊失敗
     */
    public static WebElement one_Core_two_GB(WebDriver driver)throws Exception{
        element = driver.findElement(getElementUtil.getLocator("paas.newinstance.1c2gb"));
        highLightElement(driver, element);
        return element;
    }
    // Msyql Log Page

    /**
     *
     * @param driver 瀏覽器驅動
     * @return 返回展開按鈕
     * @throws Exception 定位失敗
     */
    public static WebElement extend_Button_in_Log_Page(WebDriver driver)throws Exception{
        element = driver.findElement(getElementUtil.getLocator("paas.mysqllog.extendbutton"));
        highLightElement(driver, element);
        return element;
    }

    /**
     *
     * @param driver 瀏覽器驅動
     * @return 返回第一個日期輸入視窗
     * @throws Exception 定位失敗
     */
    public static WebElement datefrom_in_Log_Page(WebDriver driver)throws Exception{
        element = driver.findElement(getElementUtil.getLocator("paas.mysqllog.datefrom"));
        highLightElement(driver, element);
        return element;
    }

    /**
     *
     * @param driver 瀏覽器驅動
     * @return 返回日曆浮動視窗的日期input窗
     * @throws Exception 定位失敗
     */
    public static WebElement datefrom_by_Date_in_Log_Page(WebDriver driver)throws Exception{
        element = driver.findElement(getElementUtil.getLocator("paas.mysqllog.datefromdate"));
        highLightElement(driver, element);
        return element;
    }

    /**
     *
     * @param driver 瀏覽器驅動
     * @return 返回日曆浮動視窗中的時間input窗
     * @throws Exception 定位失敗
     */
    public static WebElement datefrom_by_Time_in_Log_Page(WebDriver driver)throws Exception{
        element = driver.findElement(getElementUtil.getLocator("paas.mysqllog.datefromtime"));
        highLightElement(driver, element);
        return element;
    }

    /**
     *
     * @param driver 瀏覽器驅動
     * @return 返回日曆浮動視窗的“確定”按鈕
     * @throws Exception 定位失敗
     */
    public static WebElement datefrom_Sure_Button_in_Log_Page(WebDriver driver)throws Exception{
        element = driver.findElement(getElementUtil.getLocator("paas.mysqllog.datefromsurebutton"));
        highLightElement(driver, element);
        return element;
    }

    /**
     *
     * @param driver 瀏覽器驅動
     * @return 返回“篩選” 按鈕
     * @throws Exception 定位失敗
     */
    public static WebElement search_Button_in_Log_Page(WebDriver driver)throws Exception{
        element = driver.findElement(getElementUtil.getLocator("paas.mysqllog.searchebutton"));
        highLightElement(driver, element);
        return element;
    }
}

五、測試程式碼

package testscript;
import org.apache.log4j.xml.DOMConfigurator;
import org.openqa.selenium.*;
import org.testng.Assert;
import org.testng.annotations.*;
import util.KeyActionsUtil;
import static util.KeyActionsUtil.*;
import java.util.List;
import static appmodule.MysqlService.linkToMysqlPage;
import static util.KeyBoardUtil.pressTabKey;
import static util.LogUtil.info;
import static pageobject.resourcemanagement.MySQLService.*;
import static util.ScrollBarUtil.scrolltoBottom;
import static util.WaitElementUtil.sleep;
// @Listeners({util.TestReport.class})
public class Test_Mysql {

    static {
        DOMConfigurator.configure("log4j.xml");
    }
    @BeforeClass
    public void setUp()throws Exception {
        WebDriver driver = KeyActionsUtil.initBrowser("chrome");
        linkToMysqlPage(driver, "yangdawei", "alex005x");
        sleep(2000);
    }

    @Test(priority = 0, description = "測試建立mysql資料庫服務1CPU2G")
    public void test_CreateMysqlInstance() throws Exception {
        create_New_Instance_Button(driver).click();
        info("點選建立例項按鈕...");
        sleep(1000);
        info("等待3秒...");
        instance_Name_in_Create_Instance_Dialog(driver).sendKeys("automationtest");
        info("輸入例項名:automationtesta");
        sleep(1000);
        info("等待3秒...");
        //頁面存在相同屬性的元素,取所有放到list裡,用序號操作
        List<WebElement> radios = driver.findElements(By.className("el-radio-button__inner"));
        radios.get(1).click();
        sleep(1000);
        info("選擇資料庫版本5.7...");
        instance_Standard_in_Create_Instance_Dialog(driver).click();
        info("點選例項規格...");
        sleep(2000);
        info("等待2秒...");
        one_Core_two_GB(driver).click();
        info("選擇1CPU2GB...");
        storage_Space_in_Create_Instance_Dialog(driver).clear();
        info("清空儲存空間欄位...");
        storage_Space_in_Create_Instance_Dialog(driver).sendKeys("1");
        info("輸入1G....");
        scrolltoBottom(driver);
        sleep(2000);
        pressTabKey();
        outsideaccess_Checkbox_in_Create_Instance_Dialog(driver).click();
        info("選擇外部連結...");
        password_in_Create_Instance_Dialog(driver).sendKeys("111111");
        info("輸入密碼111111...");
        repassword_in_Create_Instance_Dialog(driver).sendKeys("111111");
        info("確認密碼111111...");
        description_in_Create_Instance_Dialog(driver).sendKeys("automationtest");
        info("描述資訊輸入automationtest");
        sleep(2000);
        submit_Button_in_Create_Instance_Dialog(driver).sendKeys(Keys.ENTER);
        info("確認建立...");
        sleep(2000);
        refresh_Button(driver).click();
        Assert.assertTrue(driver.getPageSource().contains("automationtest"));
        Assert.assertTrue(driver.getPageSource().contains("建立中"));
    }
    @Test(priority = 1, description = "重啟mysql服務")
    public void test_RestartMysqlInstance()throws Exception {
        operation_Button(driver).click();
        info("點選列表裡最後一列的...");
        sleep(2000);
        info("等待3秒...");
        operation_Restart_Button(driver).click();
        info("點選下拉選單中的重啟按鈕...");
        sleep(2000);
        info("等待3秒...");
        restart_Confirm_Button(driver).click();
        info("點選確定按鈕...");
        sleep(2000);
        info("等待3秒...");
        Assert.assertTrue(driver.getPageSource().contains("重啟請求成功"));
        Assert.assertTrue(driver.getPageSource().contains("重啟中"));
    }

    @Test(priority = 2, description = "管理mysql服務頁面")
    public void test_Review_Basic_Mysql_Info()throws Exception{
        operation_Button(driver).click();
        info("點選列表裡最後一列的...");
        sleep(2000);
        info("等待3秒...");
        operation_Manage_Button(driver).click();
        info("點選下拉選單裡的管理按鈕...");
        sleep(2000);
        info("等待三秒");
        assertString(driver,"基本資訊");
    }
    @Test(priority = 3, description = "管理mysql服務頁面")
    public void test_Review_Mysql_Link()throws Exception{
        database_Link_Tab(driver).click();
        sleep(2000);
        Assert.assertTrue(driver.getPageSource().contains("210.13.50.105"));
    }

    @Test(priority = 4,description = "檢視Mysql日誌")
    public void test_ReviewLog()throws Exception{
        operation_Button(driver).click();
        info("點選列表裡最後一列的...");
        sleep(2000);
        info("等待3秒...");
        operation_Log_Button(driver).click();
        info("點選下拉選單中的日誌按鈕...");
        sleep(2000);
        info("等待3秒...");
        extend_Button_in_Log_Page(driver).click();
        info("點選展開按鈕...");
        sleep(2000);
        info("等待3秒...");
        datefrom_in_Log_Page(driver).click();
        info("點選第一個日期空間,彈出下拉...");
        sleep(2000);
        info("等待3秒...");
        datefrom_by_Date_in_Log_Page(driver).clear();
        datefrom_by_Date_in_Log_Page(driver).sendKeys("2018-09-01");
        info("輸入日期”2018-09-01");
        sleep(2000);
        info("等待3秒...");
        datefrom_Sure_Button_in_Log_Page(driver).click();
        info("點選確定按鈕...");
        sleep(2000);
        info("等待3秒...");
        search_Button_in_Log_Page(driver).click();
        info("點選篩選按鈕...");
        sleep(2000);
        info("等待3秒...");
        Assert.assertTrue(driver.getPageSource().contains("Initializing database"));

    }

    @Test(priority = 5, description = "檢視Mysql服務監控")
    public void test_MonitorMysqlService()throws Exception{
        operation_Button(driver).click();
        info("點選列表裡最後一列的...");
        sleep(3000);
        info("等待3秒...");
        operation_Monitor_Button(driver).click();
        info("點選下拉選單裡的監控按鈕...");
        sleep(3000);
        info("等待3秒...");
    }

    @Test(priority = 6, description = "釋放mysql服務")
    public void test_ReleaseMysqlService()throws Exception{
        operation_Button(driver).click();
        info("點選列表裡最後一列的...");
        sleep(3000);
        info("等待3秒...");
        operation_Release_Button(driver).click();
        info("點選下拉選單裡的釋放按鈕...");
        sleep(3000);
        info("等待3秒...");
        release_Confirm_Button(driver).click();
        info("點選確定按鈕...");
        sleep(3000);
        info("等待3秒...");
        Assert.assertTrue(driver.getPageSource().contains("操作成功"));
        Assert.assertTrue(driver.getPageSource().contains("刪除中"));
    }

    @AfterClass
    public void afterMethod(){
        driver.quit();
    }
}