public UITestSuite[] GetTestSuites(string filename, string filename2) { List <UITestSuite> testSuites = new List <UITestSuite>(); var dataProvider = new ExcelStorage(typeof(UIDataRaw)); dataProvider.FileName = filename; dataProvider.StartRow = 2; dataProvider.StartColumn = 1; var sequenceList = new List <UICommandContainer>(); var list = GetSequencesFromMaster(filename); var sequences = GetCommandSequences(filename2, list); foreach (var sequence in sequences.Sequences) { sequenceList.Add(sequence.Value); } foreach (var sheetName in Utility.GetExcelSheetNames(filename)) { dataProvider.SheetName = sheetName; var data = (UIDataRaw[])dataProvider.ExtractRecords(); var props = data.FirstOrDefault().GetType().GetProperties(); var orderedSequences = new SerializableDictionary <int, UICommandContainer>(); UITestSuite testSuite = null; for (int i = 0; i < data.Length; i++) { TestCase testCase = null; for (int x = 0; x < props.Count(); x++) { object val = data[i].GetType().GetProperty(props[x].Name).GetValue(data[i], null); if (x == 0 && val != null) { if (Utility.IsAllUpper(val.ToString())) { // add the last test case before creating new test suite and test case if (testCase != null && !string.IsNullOrEmpty(testCase.GroupName)) { testSuite.Add(testCase.GroupName, testCase); testCase = new TestCase(); } // add the previous test suite before creating a new one if (testSuite != null) { testSuites.Add(testSuite); } // get the suite name testSuite = new UITestSuite(); testSuite.Name = val.ToString(); break; } object testcaseEnabled = data[i].GetType().GetProperty(props[x + 1].Name).GetValue(data[i], null); if (testcaseEnabled == null || (testcaseEnabled.ToString().ToLower() != "y" && testcaseEnabled.ToString().ToLower() != "yes")) { continue; // this testcase is NOT enabled, so we skip processing } // get the testcase name testCase = new TestCase(); testCase.GroupName = val.ToString(); } if (x > 1 && val != null && testCase != null) { int sequencePosition = -1; var sequencesPositions = val.ToString().Split(','); foreach (var sPosition in sequencesPositions) { if (int.TryParse(sPosition, out sequencePosition)) { // get the ordered sequences for the test case var seq = sequenceList[x - (dataProvider.StartColumn + 1)]; //testCase.CommandGroups.Sequences.Add(seq.Name,new UICommandContainer(seq.Name, seq.Commands.ToArray())); orderedSequences.Add(sequencePosition, seq); } } } } // add testcase after constructed. Skip test suites if (testCase != null && !string.IsNullOrEmpty(testCase.GroupName)) { foreach (var uiCommandContainer in orderedSequences.OrderBy(x => x.Key)) { testCase.CommandGroups.Sequences.Add(uiCommandContainer.Value.Name + "(" + uiCommandContainer.Key.ToString() + ")", uiCommandContainer.Value); } orderedSequences = new SerializableDictionary <int, UICommandContainer>(); testSuite.Add(testCase.GroupName, testCase); testCase = new TestCase(); } } // add the last test suite if (testSuite != null && testSuite.Count > 0) { testSuites.Add(testSuite); } } return(testSuites.ToArray()); }
public UITestSuite[] GetTestSuites(string filename, string filename2) { List<UITestSuite> testSuites = new List<UITestSuite>(); var dataProvider = new ExcelStorage(typeof(UIDataRaw)); dataProvider.FileName = filename; dataProvider.StartRow = 2; dataProvider.StartColumn = 1; var sequenceList = new List<UICommandContainer>(); var list = GetSequencesFromMaster(filename); var sequences = GetCommandSequences(filename2, list); foreach (var sequence in sequences.Sequences) { sequenceList.Add(sequence.Value); } foreach (var sheetName in Utility.GetExcelSheetNames(filename)) { dataProvider.SheetName = sheetName; var data = (UIDataRaw[])dataProvider.ExtractRecords(); var props = data.FirstOrDefault().GetType().GetProperties(); var orderedSequences = new SerializableDictionary<int, UICommandContainer>(); UITestSuite testSuite = null; for (int i = 0; i < data.Length; i++) { TestCase testCase = null; for (int x = 0; x < props.Count(); x++) { object val = data[i].GetType().GetProperty(props[x].Name).GetValue(data[i], null); if (x==0 && val != null ) { if (Utility.IsAllUpper(val.ToString())) { // add the last test case before creating new test suite and test case if (testCase != null && !string.IsNullOrEmpty(testCase.GroupName)) { testSuite.Add(testCase.GroupName, testCase); testCase = new TestCase(); } // add the previous test suite before creating a new one if (testSuite != null) testSuites.Add(testSuite); // get the suite name testSuite = new UITestSuite(); testSuite.Name = val.ToString(); break; } object testcaseEnabled = data[i].GetType().GetProperty(props[x+1].Name).GetValue(data[i], null); if (testcaseEnabled == null || ( testcaseEnabled.ToString().ToLower() != "y" && testcaseEnabled.ToString().ToLower() != "yes")) continue; // this testcase is NOT enabled, so we skip processing // get the testcase name testCase = new TestCase(); testCase.GroupName = val.ToString(); } if (x>1 && val != null && testCase!=null) { int sequencePosition = -1; var sequencesPositions = val.ToString().Split(','); foreach (var sPosition in sequencesPositions) { if (int.TryParse(sPosition, out sequencePosition)) { // get the ordered sequences for the test case var seq = sequenceList[x - (dataProvider.StartColumn + 1)]; //testCase.CommandGroups.Sequences.Add(seq.Name,new UICommandContainer(seq.Name, seq.Commands.ToArray())); orderedSequences.Add(sequencePosition, seq); } } } } // add testcase after constructed. Skip test suites if (testCase!=null && !string.IsNullOrEmpty(testCase.GroupName)) { foreach (var uiCommandContainer in orderedSequences.OrderBy(x=>x.Key)) { testCase.CommandGroups.Sequences.Add(uiCommandContainer.Value.Name+"("+uiCommandContainer.Key.ToString()+")", uiCommandContainer.Value); } orderedSequences = new SerializableDictionary<int, UICommandContainer>(); testSuite.Add(testCase.GroupName, testCase); testCase = new TestCase(); } } // add the last test suite if (testSuite != null&&testSuite.Count>0) testSuites.Add(testSuite); } return testSuites.ToArray(); }
public CommandExecutionResult Execute(UITestSuite[] testSuites, WebAutoConfiguration configuration) { if (!Directory.Exists(configuration.ResultsFolder)) Directory.CreateDirectory(configuration.ResultsFolder); CommandExecutionResult result = new CommandExecutionResult { CommandResult = CommandResult.Success, Message = string.Empty }; Assembly assembly = Assembly.LoadFrom("WebAuto.Commands.dll"); var uiMap = Repository.GetUIMap(configuration.UIMapFile); foreach (var testSuite in testSuites) { Console.WriteLine(testSuite.Name); foreach (var testcase in testSuite) { Console.WriteLine(string.Format(" {0}", testcase.Value.GroupName)); var dataBucket = Repository.GetData(Path.Combine(configuration.DataDirectory, testcase.Value.GroupName + configuration.FileExtension)); IWebDriver driver = null; switch (configuration.Browser) { case "firefox": driver = new FirefoxDriver(); break; case "chrome": driver = new ChromeDriver(); break; case "ie": driver = new InternetExplorerDriver(); break; case "htmlunit": driver = new RemoteWebDriver(DesiredCapabilities.HtmlUnitWithJavaScript()); break; default: driver = new RemoteWebDriver(DesiredCapabilities.HtmlUnit()); break; } driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 20)); new Utility().ResizeTest(driver); var usedData = new Dictionary<string, int>(); foreach (var sequence in testcase.Value.CommandGroups.Sequences) { var commandContainer = new UICommandContainer(); commandContainer.Name = sequence.Value.Name; Console.WriteLine(string.Format(" {0}", sequence.Value.Name)); if (!usedData.ContainsKey(sequence.Value.Name)) { usedData.Add(sequence.Value.Name, 1); } else { usedData[sequence.Value.Name]++; } var dataName = usedData[sequence.Value.Name] > 1 ? string.Format("{0}({1})", sequence.Value.Name.ToLower(), usedData[sequence.Value.Name]) : sequence.Value.Name.ToLower(); // check if sequence uses a list table if (dataBucket.DataTables.ContainsKey(dataName)) { var table = dataBucket.DataTables[dataName]; foreach (var dataValue in table) { foreach (var command in sequence.Value.Commands) { var c = new UICommand() { CommandName = command.CommandName, Description = command.Description ?? string.Empty, Target = command.Target ?? string.Empty, Value = command.Value ?? string.Empty }; var cmd = PrepareCommand(c, dataValue, uiMap); Console.WriteLine(string.Format(" {0} {1} {2}", cmd.CommandName, cmd.Target, cmd.Value)); string className = "WebAuto.Commands." + Utility.UppercaseFirst(cmd.CommandName) + "Command"; Type t = assembly.GetType(className); var cmd2 = (WebAuto.Interfaces.Command)Activator.CreateInstance(t); cmd2.CommandName = cmd.CommandName; cmd2.Description = cmd.Description; cmd2.Target = cmd.Target; cmd2.Value = cmd.Value; ((ICommand) cmd2).Execute(driver); } } } else { foreach (var command in sequence.Value.Commands) { var c = new UICommand() { CommandName = command.CommandName, Description = command.Description ?? string.Empty, Target = command.Target ?? string.Empty, Value = command.Value ?? string.Empty }; var cmd = PrepareCommand(command, dataBucket.DataValues[dataName], uiMap); Console.WriteLine(string.Format(" {0} {1} {2}", cmd.CommandName, cmd.Target, cmd.Value)); string className = "WebAuto.Commands." + Utility.UppercaseFirst(cmd.CommandName) + "Command"; Type t = assembly.GetType(className); var cmd2 = (WebAuto.Interfaces.Command)Activator.CreateInstance(t); cmd2.CommandName = cmd.CommandName; cmd2.Description = cmd.Description; cmd2.Target = cmd.Target; cmd2.Value = cmd.Value; ((ICommand)cmd2).Execute(driver); } } } driver.Close(); } } return result; }