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 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;
}
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();
}
}
}
}
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();
}
}
}
}