public override void Run(TestContainer container) { try { //* add for IsExecuteCommand start if (!base.IsCommandContinue(container)) { this.PassTest = true; this.SkipTest = true; return; } //* add for IsExecuteCommand end string invokeMethodName; string invokeParameter; UICommandHelper cmdHelp = new UICommandHelper(); cmdHelp.ExtractMethodName(base.GetParameter("Target"), out invokeMethodName, out invokeParameter); By by = typeof(By).GetMethod(invokeMethodName).Invoke(null, new[] { invokeParameter }) as By; WebDriverWait wait = new WebDriverWait(container.Driver, TimeSpan.FromSeconds(container._commandTimeout)); IWebElement element = wait.Until(ExpectedConditions.ElementIsVisible(by)); IWebElement checkbox = element.FindElement(by); if (checkbox.Selected) { /// TODO: Pass this.PassTest = true; } //* add for output and IsExpectedFail start this.Output = base.GetOutPut(this.Output.Key, this.Output, this.PassTest); //* add for output and IsExpectedFail end //* add for output and IsExpectedFail start this.PassTest = GetTestPassExpected(this.PassTest); //* add for output and IsExpectedFail end //add by zhuqianqian ScreenShot start if (!this.PassTest) { CommandFailScreenShot(container); Logging.SaveLog("CommandId:" + this.Id + "=>Expecte value:Checked" + " Actual value:NotChecked", ELogType.Info); } //add by zhuqianqian ScreenShot end } catch (Exception ex) { //todo[20150323][Tom] add log //add by zhuqianqian ScreenShot start CommandFailScreenShot(container); throw ex; //add by zhuqianqian ScreenShot end } }
public override void Run(TestContainer container) { try { //* add for IsExecuteCommand start if (!base.IsCommandContinue(container)) { this.PassTest = true; this.SkipTest = true; return; } //* add for IsExecuteCommand end string invokeMethodName; string invokeParameter; UICommandHelper cmdHelp = new UICommandHelper(); cmdHelp.ExtractMethodName(base.GetParameter("Target"), out invokeMethodName, out invokeParameter); By by = typeof(By).GetMethod(invokeMethodName).Invoke(null, new[] { invokeParameter }) as By; WebDriverWait wait = new WebDriverWait(container.Driver, TimeSpan.FromSeconds(container._commandTimeout)); IWebElement elem = wait.Until(ExpectedConditions.ElementIsVisible(by)); String filePath = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, base.GetParameter("FilePath"))); Thread.Sleep(3000); //set the document path elem.SendKeys(filePath); //container.Driver.FindElement(by).Click(); //System.Windows.Forms.SendKeys.SendWait(filePath); //System.Windows.Forms.SendKeys.SendWait(@"{Enter}"); this.PassTest = true; //* add for output and IsExpectedFail start this.Output = base.GetOutPut(this.Output.Key, this.Output, this.PassTest); //* add for output and IsExpectedFail end //* add for output and IsExpectedFail start this.PassTest = GetTestPassExpected(this.PassTest); //* add for output and IsExpectedFail end //*add for ScreenShot start if (!this.PassTest) { base.CommandFailScreenShot(container); } //*add for ScreenShot end } catch (Exception ex) { //*add for ScreenShot start base.CommandFailScreenShot(container); //*add for ScreenShot end throw ex; } }
public override void Run(TestContainer container) { try { //* add for IsExecuteCommand start if (!base.IsCommandContinue(container)) { this.PassTest = true; this.SkipTest = true; return; } //* add for IsExecuteCommand end string invokeMethodName; string invokeParameter; UICommandHelper cmdHelp = new UICommandHelper(); cmdHelp.ExtractMethodName(base.GetParameter("Target"), out invokeMethodName, out invokeParameter); By by = typeof(By).GetMethod(invokeMethodName).Invoke(null, new[] { invokeParameter }) as By; string dynamicText = base.GetParameter("PrefixValue") + System.DateTime.Now.ToString("yyyyMMddHHmmss"); WebDriverWait wait = new WebDriverWait(container.Driver, TimeSpan.FromSeconds(container._commandTimeout)); IWebElement elem = wait.Until(ExpectedConditions.ElementIsVisible(by)); elem.Clear(); elem.SendKeys(dynamicText); //if (string.IsNullOrEmpty(this.Output.Key) == false) //{ // this.Output = new KeyValuePair<String, Tuple<Type, String>>(this.Output.Key, new Tuple<Type, String>(typeof(String), dynamicText)); //} this.PassTest = true; //* add for output and IsExpectedFail start this.Output = base.GetOutPut(this.Output.Key, this.Output, this.PassTest, true, dynamicText); //* add for output and IsExpectedFail end //* add for output and IsExpectedFail start this.PassTest = GetTestPassExpected(this.PassTest); //* add for output and IsExpectedFail end //*add for ScreenShot start if (!this.PassTest) { base.CommandFailScreenShot(container); } //*add for ScreenShot end } catch (Exception ex) { //*add for ScreenShot start base.CommandFailScreenShot(container); //*add for ScreenShot end throw ex; } }
public override void Run(TestContainer container) { try { //* add for IsExecuteCommand start if (!base.IsCommandContinue(container)) { this.PassTest = true; this.SkipTest = true; return; } //* add for IsExecuteCommand end string invokeMethodName; string invokeParameter; UICommandHelper cmdHelp = new UICommandHelper(); cmdHelp.ExtractMethodName(base.GetParameter("Target"), out invokeMethodName, out invokeParameter); By by = typeof(By).GetMethod(invokeMethodName).Invoke(null, new[] { invokeParameter }) as By; String[] AttributeValue = base.GetParameter("Value").Split('@'); String AttItem = AttributeValue[0]; String AttValue = AttributeValue[1]; WebDriverWait wait = new WebDriverWait(container.Driver, TimeSpan.FromSeconds(container._commandTimeout)); IWebElement element = wait.Until(ExpectedConditions.ElementIsVisible(by)); if (AttItem != null && AttValue.Equals(element.GetAttribute(AttItem).Trim())) { /// TODO: Pass this.PassTest = true; } //* add for output and IsExpectedFail start this.Output = base.GetOutPut(this.Output.Key, this.Output, this.PassTest); //* add for output and IsExpectedFail end //* add for output and IsExpectedFail start this.PassTest = GetTestPassExpected(this.PassTest); //* add for output and IsExpectedFail end //*add for ScreenShot start if (!this.PassTest) { base.CommandFailScreenShot(container); Logging.SaveLog("CommandId:" + this.Id + "=>Expecte value:" + AttValue + " Actual value:" + element.GetAttribute(AttItem).Trim(), ELogType.Info); } //*add for ScreenShot end } catch (Exception ex) { //*add for ScreenShot start base.CommandFailScreenShot(container); //*add for ScreenShot end throw ex; } }
public override void Run(TestContainer container) { try { //* add for IsExecuteCommand start if (!base.IsCommandContinue(container)) { this.PassTest = true; this.SkipTest = true; return; } //* add for IsExecuteCommand end string invokeMethodName; string invokeParameter; UICommandHelper cmdHelp = new UICommandHelper(); cmdHelp.ExtractMethodName(base.GetParameter("Target"), out invokeMethodName, out invokeParameter); By by = typeof(By).GetMethod(invokeMethodName).Invoke(null, new[] { invokeParameter }) as By; // this makes sure the element is visible before you try to do anything // for slow loading pages WebDriverWait wait = new WebDriverWait(container.Driver, TimeSpan.FromSeconds(container._commandTimeout)); var element = wait.Until(ExpectedConditions.ElementIsVisible(by)); Actions action = new Actions(container.Driver); action.MoveToElement(element); Thread.Sleep(10000); action.Perform(); /// TODO: Pass this.PassTest = true; //* add for output and IsExpectedFail start this.Output = base.GetOutPut(this.Output.Key, this.Output, this.PassTest); //* add for output and IsExpectedFail end //* add for output and IsExpectedFail start this.PassTest = GetTestPassExpected(this.PassTest); //* add for output and IsExpectedFail end //*add for ScreenShot start if (!this.PassTest) { base.CommandFailScreenShot(container); } //*add for ScreenShot end } catch (Exception ex) { //*add for ScreenShot start base.CommandFailScreenShot(container); //*add for ScreenShot end throw ex; } }
public override void Run(TestContainer container) { try { //* add for IsExecuteCommand start if (!base.IsCommandContinue(container)) { this.PassTest = true; this.SkipTest = true; return; } //* add for IsExecuteCommand end string invokeMethodName; string invokeParameter; UICommandHelper cmdHelp = new UICommandHelper(); cmdHelp.ExtractMethodName(base.GetParameter("Target"), out invokeMethodName, out invokeParameter); By by = typeof(By).GetMethod(invokeMethodName).Invoke(null, new[] { invokeParameter }) as By; // Tell webdriver to wait WebDriverWait wait = new WebDriverWait(container.Driver, TimeSpan.FromSeconds(4)); // Test the autocomplete response - Explicit Wait IWebElement elem = wait.Until(x => x.FindElement(by)); if (elem.Displayed) { /// TODO: Pass this.PassTest = true; } //* add for output and IsExpectedFail start this.Output = base.GetOutPut(this.Output.Key, this.Output, this.PassTest); //* add for output and IsExpectedFail end //* add for output and IsExpectedFail start this.PassTest = GetTestPassExpected(this.PassTest); //* add for output and IsExpectedFail end //add by zhuqianqian ScreenShot start if (!this.PassTest) { CommandFailScreenShot(container); Logging.SaveLog("CommandId:" + this.Id + "=>Expecte value:Visible" + " Actual value:NotVisible", ELogType.Info); } //add by zhuqianqian ScreenShot end } catch (Exception ex) { //add by zhuqianqian ScreenShot start CommandFailScreenShot(container); throw ex; //add by zhuqianqian ScreenShot end } }
public override void Run(TestContainer container) { try { //* add for IsExecuteCommand start if (!base.IsCommandContinue(container)) { this.PassTest = true; this.SkipTest = true; return; } //* add for IsExecuteCommand end string invokeMethodName; string invokeParameter; UICommandHelper cmdHelp = new UICommandHelper(); cmdHelp.ExtractMethodName(base.GetParameter("Target"), out invokeMethodName, out invokeParameter); By by = typeof(By).GetMethod(invokeMethodName).Invoke(null, new[] { invokeParameter }) as By; IWebElement elem = container.Driver.FindElement(by); if (!elem.Displayed) { /// TODO: Pass this.PassTest = true; } if (string.IsNullOrEmpty(this.Output.Key) == false) { this.Output = new KeyValuePair <String, Tuple <Type, String> >(this.Output.Key, new Tuple <Type, String>(typeof(String), String.Empty)); } //* add for output and IsExpectedFail start this.Output = base.GetOutPut(this.Output.Key, this.Output, this.PassTest); //* add for output and IsExpectedFail end //* add for output and IsExpectedFail start this.PassTest = GetTestPassExpected(this.PassTest); //* add for output and IsExpectedFail end //add by zhuqianqian ScreenShot start if (!this.PassTest) { CommandFailScreenShot(container); Logging.SaveLog("CommandId:" + this.Id + "=>Expecte value:NotVisible" + " Actual value:Visible", ELogType.Info); } //add by zhuqianqian ScreenShot end } catch (Exception ex) { //add by zhuqianqian ScreenShot start CommandFailScreenShot(container); throw ex; //add by zhuqianqian ScreenShot end } }
public override void Run(TestContainer container) { try { //* add for IsExecuteCommand start if (!base.IsCommandContinue(container)) { this.PassTest = true; this.SkipTest = true; return; } //* add for IsExecuteCommand end string invokeMethodName; string invokeParameter; UICommandHelper cmdHelp = new UICommandHelper(); cmdHelp.ExtractMethodName(base.GetParameter("Target"), out invokeMethodName, out invokeParameter); By by = typeof(By).GetMethod(invokeMethodName).Invoke(null, new[] { invokeParameter }) as By; WebDriverWait wait = new WebDriverWait(container.Driver, TimeSpan.FromSeconds(container._commandTimeout)); IWebElement elem = wait.Until(ExpectedConditions.ElementIsVisible(by)); IWebElement chkBox = elem.FindElement(by); if (!chkBox.Selected) { chkBox.Click(); } this.PassTest = true; //* add for output and IsExpectedFail start this.Output = base.GetOutPut(this.Output.Key, this.Output, this.PassTest); //* add for output and IsExpectedFail end //* add for output and IsExpectedFail start this.PassTest = GetTestPassExpected(this.PassTest); //* add for output and IsExpectedFail end //*add for ScreenShot start if (!this.PassTest) { base.CommandFailScreenShot(container); } //*add for ScreenShot end } catch (Exception ex) { //*add for ScreenShot start base.CommandFailScreenShot(container); //*add for ScreenShot end throw ex; } }
public override void Run(TestContainer container) { try { //* add for IsExecuteCommand start if (!base.IsCommandContinue(container)) { this.PassTest = true; this.SkipTest = true; return; } //* add for IsExecuteCommand end string invokeMethodName; string invokeParameter; UICommandHelper cmdHelp = new UICommandHelper(); cmdHelp.ExtractMethodName(base.GetParameter("Target"), out invokeMethodName, out invokeParameter); By by = typeof(By).GetMethod(invokeMethodName).Invoke(null, new[] { invokeParameter }) as By; if (IsElementPresent(container, by) == false) { /// TODO: Pass this.PassTest = true; } //* add for output and IsExpectedFail start this.Output = base.GetOutPut(this.Output.Key, this.Output, this.PassTest); //* add for output and IsExpectedFail end //* add for output and IsExpectedFail start this.PassTest = GetTestPassExpected(this.PassTest); //* add for output and IsExpectedFail end //add by zhuqianqian ScreenShot start if (!this.PassTest) { CommandFailScreenShot(container); Logging.SaveLog("CommandId:" + this.Id + "=>Expecte value:NotPresent" + " Actual value:Present", ELogType.Info); } //add by zhuqianqian ScreenShot end } catch (Exception ex) { //add by zhuqianqian ScreenShot start CommandFailScreenShot(container); throw ex; //add by zhuqianqian ScreenShot end } }
public override void Run(TestContainer container) { try { //* add for IsExecuteCommand start if (!base.IsCommandContinue(container)) { this.PassTest = true; this.SkipTest = true; return; } //* add for IsExecuteCommand end string invokeMethodName; string invokeParameter; UICommandHelper cmdHelp = new UICommandHelper(); cmdHelp.ExtractMethodName(base.GetParameter("Target"), out invokeMethodName, out invokeParameter); By by = typeof(By).GetMethod(invokeMethodName).Invoke(null, new[] { invokeParameter }) as By; WebDriverWait wait = new WebDriverWait(container.Driver, TimeSpan.FromSeconds(container._commandTimeout)); IWebElement element = wait.Until(ExpectedConditions.ElementIsVisible(by)); bool bolFullMatch = true; //try //{ // bolFullMatch = bool.Parse(base.GetParameter("FullMatch").ToString()); //} //catch //{ //} //if (bolFullMatch) //{ // if (!(base.Parameters["Value"].ToString().Equals(element.FindElement(by).Text))) // { // /// TODO: Pass // this.PassTest = true; // } //} //else //{ // if (!(base.Parameters["Value"].ToString().Contains(element.FindElement(by).Text))) // { // /// TODO: Pass // this.PassTest = true; // } //} string text = base.GetParameter("Value").ToString(); try { bolFullMatch = bool.Parse(base.GetParameter("FullMatch").ToString()); } catch { } if (bolFullMatch) { if (!(text.Equals(element.FindElement(by).Text))) { /// TODO: Pass this.PassTest = true; } } else { if (!(element.FindElement(by).Text.Contains(text))) { /// TODO: Pass this.PassTest = true; } } //* add for output and IsExpectedFail start this.Output = base.GetOutPut(this.Output.Key, this.Output, this.PassTest); //* add for output and IsExpectedFail end //* add for output and IsExpectedFail start this.PassTest = GetTestPassExpected(this.PassTest); //* add for output and IsExpectedFail end //add by zhuqianqian ScreenShot start if (!this.PassTest) { CommandFailScreenShot(container); Logging.SaveLog("CommandId:" + this.Id + "=>Expecte value Not:" + text + " Actual value:" + element.FindElement(by).Text, ELogType.Info); } //add by zhuqianqian ScreenShot end } catch (Exception ex) { //add by zhuqianqian ScreenShot start CommandFailScreenShot(container); throw ex; //add by zhuqianqian ScreenShot end } }
public override void Run(TestContainer container) { try { //* add for IsExecuteCommand start if (!base.IsCommandContinue(container)) { this.PassTest = true; this.SkipTest = true; return; } //* add for IsExecuteCommand end string invokeMethodName; string invokeParameter; UICommandHelper cmdHelp = new UICommandHelper(); cmdHelp.ExtractMethodName(base.GetParameter("Target"), out invokeMethodName, out invokeParameter); By by = typeof(By).GetMethod(invokeMethodName).Invoke(null, new[] { invokeParameter }) as By; for (int second = 0; ; second++) { if (second >= 60) { throw new Exception("timeout"); } try { if (IsElementPresent(by, container) == false) { break; } } catch (Exception) { } Thread.Sleep(1000); } this.PassTest = true; //* add for output and IsExpectedFail start this.Output = base.GetOutPut(this.Output.Key, this.Output, this.PassTest); //* add for output and IsExpectedFail end //* add for output and IsExpectedFail start this.PassTest = GetTestPassExpected(this.PassTest); //* add for output and IsExpectedFail end //*add for ScreenShot start if (!this.PassTest) { base.CommandFailScreenShot(container); } //*add for ScreenShot end } catch (Exception ex) { //*add for ScreenShot start base.CommandFailScreenShot(container); //*add for ScreenShot end throw ex; } }
public override void Run(TestContainer container) { try { //* add for IsExecuteCommand start if (!base.IsCommandContinue(container)) { this.PassTest = true; this.SkipTest = true; return; } //* add for IsExecuteCommand end string invokeMethodName; string invokeParameter; UICommandHelper cmdHelp = new UICommandHelper(); cmdHelp.ExtractMethodName(base.GetParameter("Target"), out invokeMethodName, out invokeParameter); By by = typeof(By).GetMethod(invokeMethodName).Invoke(null, new[] { invokeParameter }) as By; WebDriverWait wait = new WebDriverWait(container.Driver, TimeSpan.FromSeconds(container._commandTimeout)); IWebElement elem = wait.Until(ExpectedConditions.ElementIsVisible(by)); bool bolPass = true; List <IWebElement> lstRows = elem.FindElements(By.TagName("tr")).ToList(); string actualValue = ""; for (int i = 1; i < lstRows.Count(); i++) //ignore header, start at row 1 { List <IWebElement> lstCells = lstRows[i].FindElements(By.TagName("td")).ToList(); try { if (int.Parse(base.GetParameter("ColumnName").ToUpper().Replace("COLUMN", "")) >= lstCells.Count) { bolPass = false; } else if (int.Parse(base.GetParameter("ColumnName").ToUpper().Replace("COLUMN", "")) < 0) { bolPass = false; } } catch { bolPass = false; } for (int j = 0; j < lstCells.Count; j++) { if (base.GetParameter("ColumnName").ToUpper().Equals("COLUMN" + j.ToString())) { try { IWebElement chkElem = lstCells[j].FindElement(By.TagName(base.GetParameter("TagName"))); bolPass = false; actualValue = lstCells[j].GetAttribute("innerHTML") + ","; } catch { } } } } this.PassTest = bolPass; //* add for output and IsExpectedFail start this.Output = base.GetOutPut(this.Output.Key, this.Output, this.PassTest); //* add for output and IsExpectedFail end //* add for output and IsExpectedFail start this.PassTest = GetTestPassExpected(this.PassTest); //* add for output and IsExpectedFail end //add by zhuqianqian ScreenShot start if (!this.PassTest) { CommandFailScreenShot(container); Logging.SaveLog("CommandId:" + this.Id + "=>Expecte value Not:" + base.GetParameter("TagName") + " Actual value:" + actualValue, ELogType.Info); } //add by zhuqianqian ScreenShot end } catch (Exception ex) { //add by zhuqianqian ScreenShot start CommandFailScreenShot(container); throw ex; //add by zhuqianqian ScreenShot end } }
public override void Run(TestContainer container) { try { //* add for IsExecuteCommand start if (!base.IsCommandContinue(container)) { this.PassTest = true; this.SkipTest = true; return; } //* add for IsExecuteCommand end string invokeMethodName; string invokeParameter; UICommandHelper cmdHelp = new UICommandHelper(); cmdHelp.ExtractMethodName(base.GetParameter("Target"), out invokeMethodName, out invokeParameter); By by = typeof(By).GetMethod(invokeMethodName).Invoke(null, new[] { invokeParameter }) as By; DataTable dtWeb = new DataTable(); WebDriverWait wait = new WebDriverWait(container.Driver, TimeSpan.FromSeconds(container._commandTimeout)); IWebElement elem = wait.Until(ExpectedConditions.ElementIsVisible(by)); List <IWebElement> lstHeader = elem.FindElements(By.TagName("th")).ToList(); //Treat header like a row for (int i = 0; i < lstHeader.Count(); i++) { dtWeb.Columns.Add("Column" + i.ToString()); } DataRow drHeader = dtWeb.NewRow(); for (int i = 0; i < lstHeader.Count(); i++) { drHeader[i] = lstHeader[i].Text; } dtWeb.Rows.Add(drHeader); List <IWebElement> lstRows = elem.FindElements(By.TagName("tr")).ToList(); for (int i = 1; i < lstRows.Count(); i++) //ignore header, start at row 1 { DataRow drWeb = dtWeb.NewRow(); List <IWebElement> lstCells = lstRows[i].FindElements(By.TagName("td")).ToList(); for (int j = 0; j < lstCells.Count; j++) { if (lstCells[j].Text.Trim().Equals("")) { /// TODO try { drWeb[j] = lstCells[j].FindElement(By.TagName("i")).GetAttribute("class"); } catch { drWeb[j] = lstCells[j].Text; } } else { drWeb[j] = lstCells[j].Text; } } dtWeb.Rows.Add(drWeb); } string jsonString = ""; //if (String.IsNullOrEmpty(this.Output.Key) == false) //{ // var json = dtWeb.SerializeToJSon(); // this.Output = new KeyValuePair<String, Tuple<Type, String>>(this.Output.Key, new Tuple<Type, String>(typeof(List<Dictionary<String, String>>), json)); //} this.PassTest = true; if (String.IsNullOrEmpty(this.Output.Key) == false) { jsonString = dtWeb.SerializeToJSon(); } //* add for output and IsExpectedFail start this.Output = base.GetOutPut(this.Output.Key, this.Output, this.PassTest, true, jsonString); //* add for output and IsExpectedFail end //* add for output and IsExpectedFail start this.PassTest = GetTestPassExpected(this.PassTest); //* add for output and IsExpectedFail end //*add for ScreenShot start if (!this.PassTest) { base.CommandFailScreenShot(container); } //*add for ScreenShot end } catch (Exception ex) { //*add for ScreenShot start base.CommandFailScreenShot(container); //*add for ScreenShot end throw ex; } }
public override void Run(TestContainer container) { try { //* add for IsExecuteCommand start if (!base.IsCommandContinue(container)) { this.PassTest = true; this.SkipTest = true; return; } //* add for IsExecuteCommand end string invokeMethodName; string invokeParameter; UICommandHelper cmdHelp = new UICommandHelper(); cmdHelp.ExtractMethodName(base.GetParameter("Target"), out invokeMethodName, out invokeParameter); By by = typeof(By).GetMethod(invokeMethodName).Invoke(null, new[] { invokeParameter }) as By; WebDriverWait wait = new WebDriverWait(container.Driver, TimeSpan.FromSeconds(container._commandTimeout)); IWebElement element = wait.Until(ExpectedConditions.ElementIsVisible(by)); var selectElement = new SelectElement(element.FindElement(by)); string[] targetValue = base.GetParameter("Value").Split(','); string[] sourceValue = selectElement.Options.Select(p => p.Text).ToArray(); string actualValue = ""; for (int i = 0; i < sourceValue.Length; i++) { actualValue = actualValue + sourceValue[i] + ","; } if (actualValue.Length > 0) { actualValue = actualValue.Substring(0, actualValue.Length - 1); } //if (targetValue.SequenceEqual(selectElement.Options.Select(p => p.Text).ToArray())) if (targetValue.SequenceEqual(sourceValue)) { /// TODO: Pass this.PassTest = true; } //* add for output and IsExpectedFail start this.Output = base.GetOutPut(this.Output.Key, this.Output, this.PassTest); //* add for output and IsExpectedFail end //* add for output and IsExpectedFail start this.PassTest = GetTestPassExpected(this.PassTest); //* add for output and IsExpectedFail end //add by zhuqianqian ScreenShot start if (!this.PassTest) { CommandFailScreenShot(container); Logging.SaveLog("CommandId:" + this.Id + "=>Expecte value:" + base.GetParameter("Value") + " Actual value:" + actualValue, ELogType.Info); } //add by zhuqianqian ScreenShot end } catch (Exception ex) { //add by zhuqianqian ScreenShot start CommandFailScreenShot(container); throw ex; //add by zhuqianqian ScreenShot end } }
public override void Run(TestContainer container) { try { //* add for IsExecuteCommand start if (!base.IsCommandContinue(container)) { this.PassTest = true; this.SkipTest = true; return; } //* add for IsExecuteCommand end string invokeMethodName; string invokeParameter; UICommandHelper cmdHelp = new UICommandHelper(); cmdHelp.ExtractMethodName(base.GetParameter("Target"), out invokeMethodName, out invokeParameter); By by = typeof(By).GetMethod(invokeMethodName).Invoke(null, new[] { invokeParameter }) as By; WebDriverWait wait = new WebDriverWait(container.Driver, TimeSpan.FromSeconds(container._commandTimeout)); var element = wait.Until(ExpectedConditions.ElementIsVisible(by)); //find tooltip if (base.GetParameter("Value").Equals(container.Driver.FindElement(by).GetAttribute("data-original-title").Trim())) { WebDriverWait wait2 = new WebDriverWait(container.Driver, TimeSpan.FromSeconds(container._commandTimeout)); var element2 = wait2.Until(ExpectedConditions.ElementIsVisible(By.XPath("//div[contains(@class,'tooltip')]"))); if (IsElementPresent(By.XPath("//div[contains(@class,'tooltip')]"), container)) { /// TODO: Pass this.PassTest = true; } } //* add for output and IsExpectedFail start this.Output = base.GetOutPut(this.Output.Key, this.Output, this.PassTest); //* add for output and IsExpectedFail end //* add for output and IsExpectedFail start this.PassTest = GetTestPassExpected(this.PassTest); //* add for output and IsExpectedFail end //add by zhuqianqian ScreenShot start if (!this.PassTest) { CommandFailScreenShot(container); Logging.SaveLog("CommandId:" + this.Id + "=>Expecte value:" + base.GetParameter("Value") + " Actual value:" + container.Driver.FindElement(by).GetAttribute("data-original-title").Trim(), ELogType.Info); } //add by zhuqianqian ScreenShot end } catch (Exception ex) { //add by zhuqianqian ScreenShot start CommandFailScreenShot(container); throw ex; //add by zhuqianqian ScreenShot end } }
public override void Run(TestContainer container) { try { //* add for IsExecuteCommand start if (!base.IsCommandContinue(container)) { this.PassTest = true; this.SkipTest = true; return; } //* add for IsExecuteCommand end string invokeMethodName; string invokeParameter; UICommandHelper cmdHelp = new UICommandHelper(); cmdHelp.ExtractMethodName(base.GetParameter("Target"), out invokeMethodName, out invokeParameter); By by = typeof(By).GetMethod(invokeMethodName).Invoke(null, new[] { invokeParameter }) as By; DataTable dtWeb = new DataTable(); WebDriverWait wait = new WebDriverWait(container.Driver, TimeSpan.FromSeconds(container._commandTimeout)); IWebElement elem = wait.Until(ExpectedConditions.ElementIsVisible(by)); List <IWebElement> lstHeader = elem.FindElements(By.TagName("th")).ToList(); //Treat header like a row for (int i = 0; i < lstHeader.Count(); i++) { dtWeb.Columns.Add("Column" + i.ToString()); } DataRow drHeader = dtWeb.NewRow(); for (int i = 0; i < lstHeader.Count(); i++) { drHeader[i] = lstHeader[i].Text; } dtWeb.Rows.Add(drHeader); List <IWebElement> lstRows = elem.FindElements(By.TagName("tr")).ToList(); for (int i = 1; i < lstRows.Count(); i++) //ignore header, start at row 1 { DataRow drWeb = dtWeb.NewRow(); List <IWebElement> lstCells = lstRows[i].FindElements(By.TagName("td")).ToList(); for (int j = 0; j < lstCells.Count; j++) { if (lstCells[j].Text.Trim().Equals("")) { /// TODO try { drWeb[j] = lstCells[j].FindElement(By.TagName("i")).GetAttribute("class"); } catch { drWeb[j] = lstCells[j].Text; } } else { drWeb[j] = lstCells[j].Text; } } dtWeb.Rows.Add(drWeb); } List <string> lstSource = new List <string>(); List <string> lstTarget = new List <string>(); for (int i = 1; i < dtWeb.Rows.Count; i++) { lstSource.Add(dtWeb.Rows[i][base.GetParameter("ColumnName")].ToString()); lstTarget.Add(dtWeb.Rows[i][base.GetParameter("ColumnName")].ToString()); } string strActual = ""; if (base.GetParameter("SortBy").ToUpper().Equals("ASC")) { lstTarget = lstTarget.OrderBy(p => p).ToList(); strActual = "DESC"; } else { lstTarget = lstTarget.OrderByDescending(p => p).ToList(); strActual = "ASC"; } if (lstTarget.SequenceEqual(lstSource)) { this.PassTest = true; } //* add for output and IsExpectedFail start this.Output = base.GetOutPut(this.Output.Key, this.Output, this.PassTest); //* add for output and IsExpectedFail end //* add for output and IsExpectedFail start this.PassTest = GetTestPassExpected(this.PassTest); //* add for output and IsExpectedFail end //add by zhuqianqian ScreenShot start if (!this.PassTest) { CommandFailScreenShot(container); Logging.SaveLog("CommandId:" + this.Id + "=>Expecte value:" + base.GetParameter("SortBy").ToUpper() + " Actual value:" + strActual, ELogType.Info); } //add by zhuqianqian ScreenShot end } catch (Exception ex) { //add by zhuqianqian ScreenShot start CommandFailScreenShot(container); throw ex; //add by zhuqianqian ScreenShot end } }
public override void Run(TestContainer container) { try { //* add for IsExecuteCommand start if (!base.IsCommandContinue(container)) { this.PassTest = true; this.SkipTest = true; return; } //* add for IsExecuteCommand end string invokeMethodName; string invokeParameter; UICommandHelper cmdHelp = new UICommandHelper(); cmdHelp.ExtractMethodName(base.GetParameter("Target"), out invokeMethodName, out invokeParameter); By by = typeof(By).GetMethod(invokeMethodName).Invoke(null, new[] { invokeParameter }) as By; Thread.Sleep(1000); IWebElement element = container.Driver.FindElement(by); //Console.WriteLine(element.GetAttribute("Value")); //Console.WriteLine(base.Parameters["Value"]); //edit: all the way. 38 rows of 45-49 OpenQA.Selenium.IJavaScriptExecutor js = (OpenQA.Selenium.IJavaScriptExecutor)container.Driver; if (base.GetParameter("Value").Equals(element.GetAttribute("Value").Trim())) { /// TODO: Pass this.PassTest = true; } else if (base.GetParameter("Value").Equals(js.ExecuteScript("return $('#" + invokeParameter.ToString() + "').val()").ToString().Trim())) { /// TODO: Pass this.PassTest = true; } //* add for output and IsExpectedFail start this.Output = base.GetOutPut(this.Output.Key, this.Output, this.PassTest); //* add for output and IsExpectedFail end //* add for output and IsExpectedFail start this.PassTest = GetTestPassExpected(this.PassTest); //* add for output and IsExpectedFail end //add by zhuqianqian ScreenShot start if (!this.PassTest) { CommandFailScreenShot(container); Logging.SaveLog("CommandId:" + this.Id + "=>Expecte value:" + base.GetParameter("Value") + " Actual value:" + js.ExecuteScript("return $('#" + invokeParameter.ToString() + "').val()").ToString().Trim(), ELogType.Info); } //add by zhuqianqian ScreenShot end } catch (Exception ex) { //add by zhuqianqian ScreenShot start CommandFailScreenShot(container); throw ex; //add by zhuqianqian ScreenShot end } }
public override void Run(TestContainer container) { try { //* add for IsExecuteCommand start if (!base.IsCommandContinue(container)) { this.PassTest = true; this.SkipTest = true; return; } //* add for IsExecuteCommand end //Calendar locator string invokeMethodName; string invokeParameter; UICommandHelper cmdHelp = new UICommandHelper(); cmdHelp.ExtractMethodName(base.GetParameter("Target"), out invokeMethodName, out invokeParameter); By by = typeof(By).GetMethod(invokeMethodName).Invoke(null, new[] { invokeParameter }) as By; WebDriverWait wait = new WebDriverWait(container.Driver, TimeSpan.FromSeconds(container._commandTimeout)); IWebElement elem = wait.Until(ExpectedConditions.ElementIsVisible(by)); //Next Month Locator string invokeNextMonthMethodName; string invokeNextMonthParameter; cmdHelp.ExtractMethodName(base.GetParameter("NextMonthLocator"), out invokeNextMonthMethodName, out invokeNextMonthParameter); By byOfNextMonth = typeof(By).GetMethod(invokeNextMonthMethodName).Invoke(null, new[] { invokeNextMonthParameter }) as By; IWebElement elemNextMonth = wait.Until(ExpectedConditions.ElementIsVisible(byOfNextMonth)); //Previous Month Locator string invokePreMonthMethodName; string invokePreMonthParameter; cmdHelp.ExtractMethodName(base.GetParameter("PreMonthLocator"), out invokePreMonthMethodName, out invokePreMonthParameter); By byOfPreMonth = typeof(By).GetMethod(invokePreMonthMethodName).Invoke(null, new[] { invokePreMonthParameter }) as By; IWebElement elemPreMonth = wait.Until(ExpectedConditions.ElementIsVisible(byOfPreMonth)); DateTime dtSelectDate = DateTime.ParseExact(base.GetParameter("Date"), "yyyy-MM-dd", CultureInfo.CurrentUICulture); int yearDiff = dtSelectDate.Year - DateTime.UtcNow.Year; int monthDiff = dtSelectDate.Month - DateTime.UtcNow.Month; int dayDiff = dtSelectDate.Day - DateTime.UtcNow.Day; int selectDay = dtSelectDate.Day; bool isFuture = true; int clickMonthTimes = 0; int totalDiffMonth = yearDiff * 12 + monthDiff; if (totalDiffMonth > 0) { clickMonthTimes = totalDiffMonth; } else if (totalDiffMonth == 0) { clickMonthTimes = 0; if (dayDiff <= 0) { isFuture = false; } } else { clickMonthTimes = -(totalDiffMonth); isFuture = false; } if (isFuture) { //IWebElement elemNextMonth = elem.FindElement(By.XPath("thead/tr[1]/th[3]")); for (int i = 0; i < clickMonthTimes; i++) { elemNextMonth.Click(); } } else { //IWebElement elemPreviousMonth = elem.FindElement(By.XPath("thead/tr[1]/th[1]")); for (int i = 0; i < clickMonthTimes; i++) { elemPreMonth.Click(); } } //Select Day bool isFindFirstDay = false; bool isFindoutAndClick = false; List <IWebElement> lstRows = elem.FindElement(By.TagName("tbody")).FindElements(By.TagName("tr")).ToList(); for (int i = 0; i < lstRows.Count(); i++) { List <IWebElement> lstCells = lstRows[i].FindElements(By.TagName("td")).ToList(); for (int j = 0; j < lstCells.Count; j++) { if (lstCells[j].Text.Trim().Equals("1")) { isFindFirstDay = true; } if (isFindFirstDay && lstCells[j].Text.Trim().Equals(selectDay.ToString())) { lstCells[j].Click(); isFindoutAndClick = true; break; } } if (isFindoutAndClick) { break; } } this.PassTest = true; //* add for output and IsExpectedFail start this.Output = base.GetOutPut(this.Output.Key, this.Output, this.PassTest); //* add for output and IsExpectedFail end //* add for output and IsExpectedFail start this.PassTest = GetTestPassExpected(this.PassTest); //* add for output and IsExpectedFail end //*add for ScreenShot start if (!this.PassTest) { base.CommandFailScreenShot(container); } //*add for ScreenShot end } catch (Exception ex) { //*add for ScreenShot start base.CommandFailScreenShot(container); //*add for ScreenShot end throw ex; } }