|
| 1 | +using NUnit.Framework; |
| 2 | +using QA_Automation_Framework_Playwright.Pages; |
| 3 | +using QA_Automation_Framework_Playwright.Utilities; |
| 4 | +using Microsoft.Playwright; |
| 5 | +using AventStack.ExtentReports; |
| 6 | +using AventStack.ExtentReports.Reporter; |
| 7 | +using System.IO; |
| 8 | +using System.Threading.Tasks; |
| 9 | + |
| 10 | +namespace QA_Automation_Framework_Playwright.Tests |
| 11 | +{ |
| 12 | + public class CheckoutTests |
| 13 | + { |
| 14 | + private IPage _page; |
| 15 | + private ExtentReports _extent; |
| 16 | + private ExtentTest _test; |
| 17 | + |
| 18 | + [OneTimeSetUp] |
| 19 | + public void SetupReporting() |
| 20 | + { |
| 21 | + var htmlReporter = new ExtentHtmlReporter(Path.Combine(Directory.GetCurrentDirectory(), "Reports", "Report.html")); |
| 22 | + _extent = new ExtentReports(); |
| 23 | + _extent.AttachReporter(htmlReporter); |
| 24 | + } |
| 25 | + |
| 26 | + [SetUp] |
| 27 | + public async Task Setup() |
| 28 | + { |
| 29 | + _page = await BrowserFactory.CreatePageAsync(); |
| 30 | + _test = _extent.CreateTest(TestContext.CurrentContext.Test.Name); |
| 31 | + } |
| 32 | + |
| 33 | + [Test] |
| 34 | + public async Task ECommerce_Checkout_Flow() |
| 35 | + { |
| 36 | + var home = new HomePage(_page); |
| 37 | + var product = new ProductPage(_page); |
| 38 | + var cart = new CartPage(_page); |
| 39 | + var checkout = new CheckoutPage(_page); |
| 40 | + |
| 41 | + await home.NavigateAsync(); |
| 42 | + await home.ClickProductAsync("Samsung galaxy s6"); |
| 43 | + await product.AddToCartAsync(); |
| 44 | + await cart.GoToCartAsync(); |
| 45 | + await cart.ProceedToCheckoutAsync(); |
| 46 | + await checkout.FillOrderFormAsync("Rustam", "USA", "Tampa", "123456789012", "12", "2025"); |
| 47 | + |
| 48 | + Assert.IsTrue(await checkout.VerifyConfirmationAsync(), "Purchase confirmation not visible"); |
| 49 | + _test.Pass("Checkout flow completed successfully"); |
| 50 | + } |
| 51 | + |
| 52 | + [TearDown] |
| 53 | + public async Task TearDown() |
| 54 | + { |
| 55 | + if (TestContext.CurrentContext.Result.Outcome.Status == NUnit.Framework.Interfaces.TestStatus.Failed) |
| 56 | + { |
| 57 | + var screenshot = await ScreenshotHelper.TakeScreenshot(_page); |
| 58 | + _test.Fail("Test failed").AddScreenCaptureFromPath(screenshot); |
| 59 | + } |
| 60 | + await BrowserFactory.CloseAsync(); |
| 61 | + } |
| 62 | + |
| 63 | + [OneTimeTearDown] |
| 64 | + public void FlushReport() => _extent.Flush(); |
| 65 | + } |
| 66 | +} |
0 commit comments