Web UI自动化测试 - Selenium - base testcase

package com.wbsn.mobile.testcase.mdm;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import com.wbsn.mobile.env.*;
import com.wbsn.mobile.jselenium2.support.SeleniumDriver;
import com.wbsn.mobile.util.sshserver.ClusterSsh;
import com.wbsn.mobile.testcase.Constant;
import com.wbsn.mobile.testcase.Global;
import com.wbsn.mobile.util.ParseGlobalConfigFile;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator; 
import org.testng.annotations.*;


public class MDMBaseTest{


public static WebDriver driver;
public static SeleniumDriver sDriver;
public static ClusterSsh clusterSsh;

public Browser browser;
public String browserType;
public String browserName;

protected static Map<String, String> browserinfo = new HashMap<String, String>();
protected static Map<String, String> dbinfo = new HashMap<String, String>();
static Logger logger = Logger.getLogger(MDMBaseTest.class);

/**
* create Browser.
* @throws Exception
*/
public Browser createBrowser(String browserType){

if (browserType.equals("ie")){

return new IExplorer();

}
else if (browserType.equals("chrome")){

return new Chrome();

}
else{

   return new Firefox();
}
}

public void initLogDB(String cfgFilename, String sectionName) throws Exception{

dbinfo = ParseGlobalConfigFile.parse(cfgFilename, sectionName);

Constant.serverIP = dbinfo.get("ip");
Constant.portNumber = dbinfo.get("port");
Constant.user = dbinfo.get("username");
Constant.password = dbinfo.get("password");
Constant.databaseName = dbinfo.get("database");
Constant.integratedSecurity = false;

}

public void initBrowser(String cfgFilename, String sectionName) throws Exception{

browserinfo = ParseGlobalConfigFile.parse(cfgFilename, sectionName);
browserType = browserinfo.get("browserType");
browserName = browserinfo.get("browserName");

browser= this.createBrowser(browserType);
browser.setBrowserType(browserType);
browser.setBrowserName(browserName);
browser.setBrowserProfile(browserinfo.get("browserProfile"));
browser.setBrowserBinary(browserinfo.get("browserBinary"));

Constant.browserType = browserType;
Constant.browserName = browserName;
}

/**
* Initialize testing environment, browser, clusterSsh object.
* @throws Exception
*/
@BeforeSuite
@Parameters({"browsername", "dbname", "mdmversion", "clustername", "clusterip"})
public void initMDMTest(String browsername, String dbname, String mdmversion, String clustername, String clusterip) throws Exception{

initBrowser(Global.globalcfgfile, browsername);
initLogDB(Global.globalcfgfile, dbname);

Constant.mdmversion = mdmversion;

if (clustername.equalsIgnoreCase("21cluster")){
   Constant.url = Global.TMS_21Cluster_MDM_URL; //pointing to 21 Cluster
   Constant.selfserviceurl = Global.TMS_21Cluster_SelfServie_URL;
}
else if (clustername.equalsIgnoreCase("51cluster")){
   Constant.url = Global.TMS_51Cluster_MDM_URL; //pointing to 51 Cluster
   Constant.selfserviceurl = Global.TMS_51Cluster_SelfServie_URL;
}
else if (clustername.equalsIgnoreCase("161cluster")){
   Constant.url = Global.TMS_161Cluster_MDM_URL; //pointing to 161 Cluster
   Constant.selfserviceurl = Global.TMS_161Cluster_SelfServie_URL;
}
else if (clustername.equalsIgnoreCase("81cluster")){
   Constant.url = Global.TMS_81Cluster_MDM_URL; //pointing to 161 Cluster
   Constant.selfserviceurl = Global.TMS_81Cluster_SelfServie_URL;
}

PropertyConfigurator.configure(Global.log4jcfgfile);

driver=browser.getDriver();

driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
sDriver=new SeleniumDriver(driver);
clusterSsh=new ClusterSsh();
clusterSsh.setSshKeyLoc("mailcontrol");
Constant.clusterip = clusterip;
}

/**
* Finish test and destroy browser and clusterSsh object.
* @throws Exception
*/
@AfterSuite
public void finishMDMTest() throws Exception{

if(sDriver!=null){
sDriver.getDriver().quit();
}
//Disconnect from cluster server
if(clusterSsh!=null){
if(clusterSsh.isConnected()){
clusterSsh.close();
}
}
}
 
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值