public void AfterTest() { string screenShotPath = BaseTest.Capture(TestContext.CurrentContext.Test.Name); var status = TestContext.CurrentContext.Result.Outcome.Status; var stacktrace = string.IsNullOrEmpty(TestContext.CurrentContext.Result.StackTrace) ? "" : string.Format("<pre>{0}</pre>", TestContext.CurrentContext.Result.StackTrace); Status logstatus; switch (status) { case TestStatus.Failed: logstatus = Status.Fail; break; case TestStatus.Inconclusive: logstatus = Status.Warning; break; case TestStatus.Skipped: logstatus = Status.Skip; break; default: logstatus = Status.Pass; break; } ExtentTestManager.GetTest().Log(logstatus, "Test ended with " + logstatus + stacktrace); ExtentTestManager.GetTest().Log(logstatus, "Snapshot below: " + ExtentTestManager.GetTest().AddScreenCaptureFromPath(screenShotPath)); }
public void AddtoCart() { IList <IWebElement> list = _driver.FindElements(By.XPath("//div[@class='product-image-container']/descendant::a[@class='quick-view']"));; for (int i = 0; i < 2; i++) { Task.Delay(3000).Wait(); if (i == 0) { ((IJavaScriptExecutor)_driver).ExecuteScript("var mouseEvent = document.createEvent('MouseEvents');mouseEvent.initEvent('mouseover', true, true); arguments[0].dispatchEvent(mouseEvent);", productList); } else { ((IJavaScriptExecutor)_driver).ExecuteScript("arguments[0].scrollIntoView(true);", productList); } Actions action = new Actions(_driver); action.MoveToElement(list[i]).Click(list[i]).Build().Perform(); _driver.SwitchTo().Frame(SelectedFrame); if (BaseTest.WaitUntilElementExists(addToCart)) { string screenShotPath = BaseTest.Capture("ProductViewLoad_" + i); ExtentTestManager.GetTest().Log(Status.Pass, "Product Quick View loaded"); ExtentTestManager.GetTest().Log(Status.Pass, "Snapshot below: " + ExtentTestManager.GetTest().AddScreenCaptureFromPath(screenShotPath)); } else { string screenShotPath = BaseTest.Capture("ProductViewLoad_Failed_" + i); ExtentTestManager.GetTest().Log(Status.Fail, "Product Quick View is not loaded"); ExtentTestManager.GetTest().Log(Status.Fail, "Snapshot below: " + ExtentTestManager.GetTest().AddScreenCaptureFromPath(screenShotPath)); } addToCart.Click(); _driver.SwitchTo().DefaultContent(); if (i == 0) { if (BaseTest.WaitUntilElementExists(Continue)) { string screenShotPath = BaseTest.Capture("First_Product_Added" + i); ExtentTestManager.GetTest().Log(Status.Pass, "first product add to cart"); ExtentTestManager.GetTest().Log(Status.Pass, "Snapshot below: " + ExtentTestManager.GetTest().AddScreenCaptureFromPath(screenShotPath)); } else { string screenShotPath = BaseTest.Capture("First_Product_Added_Failed" + i); ExtentTestManager.GetTest().Log(Status.Fail, "unable to add first product to cart"); ExtentTestManager.GetTest().Log(Status.Fail, "Snapshot below: " + ExtentTestManager.GetTest().AddScreenCaptureFromPath(screenShotPath)); } Task.Delay(5000).Wait(); Continue.Click(); } else { if (BaseTest.WaitUntilElementExists(proceedToPurchase)) { string screenShotPath = BaseTest.Capture("Second_Product_Added_Failed" + i); ExtentTestManager.GetTest().Log(Status.Pass, "Second Product Added to cart"); ExtentTestManager.GetTest().Log(Status.Pass, "Snapshot below: " + ExtentTestManager.GetTest().AddScreenCaptureFromPath(screenShotPath)); } else { string screenShotPath = BaseTest.Capture("Second_Product_Added_Failed" + i); ExtentTestManager.GetTest().Log(Status.Fail, "unable to add second product to cart"); ExtentTestManager.GetTest().Log(Status.Fail, "Snapshot below: " + ExtentTestManager.GetTest().AddScreenCaptureFromPath(screenShotPath)); } Task.Delay(5000).Wait(); proceedToPurchase.Click(); } } }