/// <summary> /// Restore Database /// </summary> private void RestoreDB() { string RestoreDB = AppConfigOper.getConfigValue("RestoreDB_AfterEachTestCase"); string ServerLogPath = AppConfigOper.getConfigValue("Server_Log_Path"); string ViewerLogPath = AppConfigOper.getConfigValue("Viewer_Log_Path"); // If RestoreDB is Y, program will restore Database for Nform before scripts are executed. if (RestoreDB.Equals("Y")) { //stop Nform service Console.WriteLine("Stop Nform service..."); RunCommand("sc stop Nform"); Delay.Duration(10000); //If NformService is still running, stop Nform again. Try 3 times. for (int i = 0; i < 3; i++) { if (!isStopped()) { RunCommand("sc stop Nform"); Delay.Duration(10000); } } //First, delete log files to clean the Nform. // myLxDBOper.DeleteLogFile(ServerLogPath); // myLxDBOper.DeleteLogFile(ViewerLogPath); // Restore Database operation. // If there is any error when perform Scripts, execute the restore DB operation. myLxDBOper.RestoreDataBase(); if (myLxDBOper.GetRestoreResult() == false) { Console.WriteLine("Restore database is faild! You need to restore database manually"); } else { Console.WriteLine("Restore database is successful!"); } //start Nform service Console.WriteLine("Start Nform service..."); RunCommand("sc start Nform"); Delay.Duration(10000); //If Nform is not running, start Nform again. Try 3 times. for (int j = 0; j < 3; j++) { if (!isStarted()) { //start Nform service Console.WriteLine("Start Nform service..."); RunCommand("sc start Nform"); } } } }
/// <summary> /// Backup database /// </summary> private void BackupDB() { string RestoreDB = AppConfigOper.getConfigValue("RestoreDB_AfterEachTestCase"); string ServerLogPath = AppConfigOper.getConfigValue("Server_Log_Path"); string ViewerLogPath = AppConfigOper.getConfigValue("Viewer_Log_Path"); string DB_DbType = AppConfigOper.getConfigValue("DB_DbType"); // If RestoreDB is Y, program will restore Database for Nform before scripts are executed. if (RestoreDB.Equals("Y")) { //stop Nform service Console.WriteLine("Stop Nform service..."); string strRst = RunCommand("sc stop Nform"); //First, delete log files to clean the Nform. Delay.Duration(10000); //If NformService is still running, stop Nform again. Try 3 times. for (int i = 0; i < 3; i++) { if (!isStopped()) { RunCommand("sc stop Nform"); Delay.Duration(10000); } } myLxDBOper.DeleteLogFile(ServerLogPath); myLxDBOper.DeleteLogFile(ViewerLogPath); //Backup Database operation. Just do once before run all scripts. myLxDBOper.SetDbType(DB_DbType); myLxDBOper.BackUpDataBase(); if (myLxDBOper.GetBackUpResult() == false) { Console.WriteLine("Back up database is faild!"); } else { Console.WriteLine("Back up database is successful!"); } //start Nform service Console.WriteLine("Start Nform service..."); strRst = RunCommand("sc start Nform"); //If Nform is not running, start Nform again. Try 3 times. for (int j = 0; j < 3; j++) { if (!isStarted()) { //start Nform service Console.WriteLine("Start Nform service..."); RunCommand("sc start Nform"); } } } }
/// <summary> /// Performs the playback of actions in this module. /// </summary> /// <remarks>You should not call this method directly, instead pass the module /// instance to the <see cref="TestModuleRunner.Run(ITestModule)"/> method /// that will in turn invoke this method.</remarks> void ITestModule.Run() { Mouse.DefaultMoveTime = 300; Keyboard.DefaultKeyPressTime = 100; Delay.SpeedFactor = 1.0; LxSetup mainOp = LxSetup.getInstance(); var configs = mainOp.configs; string DetailSteps = AppConfigOper.getConfigValue("DetailSteps_InResult"); string strUserName = AppConfigOper.getConfigValue("UserName"); string strPassword = AppConfigOper.getConfigValue("Password"); string strServerName = AppConfigOper.getConfigValue("ServerName"); BackupDB(); string tsName = mainOp.getTestCaseName(); string excelPath = "keywordscripts/" + tsName + ".xlsx"; string keywordName = "keywordscripts/"; Report.Info("INfo", excelPath); mainOp.StrExcelDirve = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), excelPath); mainOp.m_strUserName = strUserName; mainOp.m_stPassword = strPassword; mainOp.m_strServerName = strServerName; mainOp.runApp();// ********* 1. run Application ********* //Copy script to Report folder string reportPath = Program.getReport(); string sourcePath = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), keywordName); string reprotFileName = reportPath + tsName + ".xlsx"; string sourceFileName = mainOp.StrExcelDirve; LxParse stepsRepository = mainOp.getSteps(); // stepsRepository.doValidate(); // ********* 2. check scripts syntax ********* int myProcess = mainOp.ProcessId; ArrayList stepList = stepsRepository.getStepsList(); bool result = true; // ********* 3. run scripts with reflection ********* try { result = LxGenericAction.performScripts(stepList, DetailSteps); } catch (Exception e) { result = false; LxLog.Error("Error", tsName + " " + e.Message.ToString()); } mainOp.setResult(); mainOp.runOverOneCase(tsName); mainOp.opXls.close(); Delay.Seconds(5); LxTearDown.closeApp(mainOp.ProcessId); // ********* 4. clean up for next running ********* RestoreDB(); // Add excel file link in Ranorex.report. string linkFile = reportPath + tsName + ".xlsx"; string html = String.Format("<a href='{0}'>{1}</a>", linkFile, tsName); Report.LogHtml(ReportLevel.Info, "Info", html); //Copy all report created by Ranorex to Nform Report folder. // XCopy(sourcePath, reportPath); System.IO.File.Copy(sourceFileName, reprotFileName, true); if (!result) { throw new Ranorex.ValidationException("The test case running failed!", null); } }
public static int Main(string[] args) { /* * if(!CheckDeviceAvailable()) * { * DialogResult dr = MessageBox.Show("Do you want to continue? Click Ok button to continue.", "Warning" , MessageBoxButtons.YesNo,MessageBoxIcon.Warning,MessageBoxDefaultButton.Button2); * if(dr == DialogResult.No) * { * return 0; * } * } * * var configs = GetConfigs (); * string CheckDevice = configs["CheckDevice_BeforeTesting"]; * string RestoreDB = configs["RestoreDB_AfterEachTestCase"]; */ /* * Get size of database for SQL SERVER * LxSQLDbOperation SQLOper = new LxSQLDbOperation(); * SqlConnection conn = new SqlConnection(); * conn.ConnectionString =@"Data Source=10.146.64.56\SQLEXPRESS;Initial Catalog=master;User ID=sa;Password=sa@2013;"; * SQLOper.OpenConnection(conn); * string NformSize = SQLOper.GetDbSize(conn, "Nform"); * string NformAlmSize = SQLOper.GetDbSize(conn, "NformAlm"); * string NformLogSize = SQLOper.GetDbSize(conn, "NformLog"); * Console.WriteLine("The size of Nform is:"+NformSize); * Console.WriteLine("The size of Nform is:"+NformAlmSize); * Console.WriteLine("The size of Nform is:"+NformLogSize); */ /* * Get size of database for SQL CE * LxCEDbOperation CEOper = new LxCEDbOperation(); * double NformAlmSize = CEOper.GetAlarmDbSize(); * double NformDataLogSize = CEOper.GetDataLogDbSize(); * Console.WriteLine("NformAlmSize is: " +NformAlmSize); * Console.WriteLine("NformDataLogSize is: " +NformDataLogSize); * */ /* * Increase database for SQLCE * LxCEDbOperation CEOper = new LxCEDbOperation(); * CEOper.IncreaseAlarmDbSize(); * CEOper.IncreaseDatalogDbSize(); * */ /* * Increase database for SQL SERVER * LxSQLDbOperation SQLOper = new LxSQLDbOperation(); * SqlConnection conn = new SqlConnection(); * conn.ConnectionString =@"Data Source=10.146.64.56\SQLEXPRESS;Initial Catalog=master;User ID=sa;Password=sa@2013;"; * SQLOper.GetDbSize(conn,"NformAlm"); * SQLOper.GetDbSize(conn,"NformLog"); * SQLOper.IncreaseAlarmDbSize(); * SQLOper.IncreaseDatalogDbSize(); * * */ /* * Get table value for SQLCE database * * LxCEDbOperation CEOper = new LxCEDbOperation(); * string dbNformName = @"Nform.sdf"; * string dbNformAlmName = @"NformAlm.sdf"; * string dbNformLogName = @"NformLog.sdf"; * string cmdVersion = @"SELECT * FROM Version;"; * string cmdAlarm = @"SELECT * FROM Alarm;"; * string cmdLog = @"SELECT * FROM DataLog;"; * CEOper.GetTableValue(dbNformName,cmdVersion); * CEOper.GetTableValue(dbNformAlmName,cmdAlarm); * CEOper.GetTableValue(dbNformLogName,cmdLog); * * */ /* * Get table value for SQLServer database * LxSQLDbOperation SQLOper = new LxSQLDbOperation(); * SqlConnection conn = new SqlConnection(); * conn.ConnectionString =@"Data Source=10.146.64.56\SQLEXPRESS;Initial Catalog=master;User ID=sa;Password=sa@2013;"; * string cmdVersion = @"use Nform;SELECT * FROM Version;"; * string cmdAlarm = @"use NformAlm;SELECT * FROM Alarm;"; * string cmdLog = @"use NformLog;SELECT * FROM DataLog;"; * string cmdGrp = @"use Nform;SELECT * FROM UsrGrp;"; * SQLOper.GetTableValue(conn,cmdVersion); * SQLOper.GetTableValue(conn,cmdGrp); * */ string CheckDevice = AppConfigOper.getConfigValue("CheckDevice_BeforeTesting"); string RestoreDB = AppConfigOper.getConfigValue("RestoreDB_AfterEachTestCase"); string runOnVM = AppConfigOper.getConfigValue("RunOnVM"); //Create Report folder string reportDir = System.IO.Directory.GetCurrentDirectory(); System.IO.DirectoryInfo reportDirect = System.IO.Directory.CreateDirectory(reportDir + @"\Report\" + "Report_" + System.DateTime.Now.ToString("yyyyMMdd_HHmmss")); string ReportPath = reportDirect.FullName + @"\"; setReport(ReportPath); // If CheckDevice is Y, program will check these ip addresses are available or not. if (CheckDevice.Equals("Y")) { //stop Nform service Console.WriteLine("Stop Nform service..."); string strRst = RunCommand("sc stop Nform"); //Be used to check devices are avalibale or not, which are configured in Device.ini LxDeviceAvailable myDeviceAvailable = new LxDeviceAvailable(); myDeviceAvailable.CheckSnmpDevice(); //myDeviceAvailable.CheckVelDevice(); //start Nform service Console.WriteLine("Start Nform service..."); strRst = RunCommand("sc start Nform"); } if (CheckDevice.Equals("Y")) { Keyboard.Enabled = false; Mouse.Enabled = false; Keyboard.AbortKey = System.Windows.Forms.Keys.Pause; NformRepository.Instance.SearchTimeout = new Duration(50000); } Keyboard.AbortKey = System.Windows.Forms.Keys.Pause; int error = 0; /* * try * { * error = TestSuiteRunner.Run(typeof(Program), Environment.CommandLine); * } * catch (Exception e) * { * MessageBox.Show("Unexpected exception occurred:"); * Report.Error("Unexpected exception occurred: " + e.ToString()); * error = -1; * } */ error = TestSuiteRunner.Run(typeof(Program), Environment.CommandLine); return(error); }