diff --git a/eShopOnWeb.sln b/eShopOnWeb.sln index 768d154..f5ac8b7 100644 --- a/eShopOnWeb.sln +++ b/eShopOnWeb.sln @@ -27,6 +27,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Web", "src\Web\Web.csproj", "{227CF035-29B0-448D-97E4-944F9EA850E5}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SeleniumTests", "tests\SeleniumTests\SeleniumTests.csproj", "{E09E981A-B73C-40FF-B120-AF37D1FB4003}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -57,6 +59,10 @@ Global {227CF035-29B0-448D-97E4-944F9EA850E5}.Debug|Any CPU.Build.0 = Debug|Any CPU {227CF035-29B0-448D-97E4-944F9EA850E5}.Release|Any CPU.ActiveCfg = Release|Any CPU {227CF035-29B0-448D-97E4-944F9EA850E5}.Release|Any CPU.Build.0 = Release|Any CPU + {E09E981A-B73C-40FF-B120-AF37D1FB4003}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E09E981A-B73C-40FF-B120-AF37D1FB4003}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E09E981A-B73C-40FF-B120-AF37D1FB4003}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E09E981A-B73C-40FF-B120-AF37D1FB4003}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -68,6 +74,7 @@ Global {0F576306-7E2D-49B7-87B1-EB5D94CFD5FC} = {15EA4737-125B-4E6E-A806-E13B7EBCDCCF} {7EFB5482-F942-4C3D-94B0-9B70596E6D0A} = {15EA4737-125B-4E6E-A806-E13B7EBCDCCF} {227CF035-29B0-448D-97E4-944F9EA850E5} = {419A6ACE-0419-4315-A6FB-B0E63D39432E} + {E09E981A-B73C-40FF-B120-AF37D1FB4003} = {15EA4737-125B-4E6E-A806-E13B7EBCDCCF} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {49813262-5DA3-4D61-ABD3-493C74CE8C2B} diff --git a/tests/SeleniumTests/ChromeDriverTests.cs b/tests/SeleniumTests/ChromeDriverTests.cs new file mode 100644 index 0000000..422233b --- /dev/null +++ b/tests/SeleniumTests/ChromeDriverTests.cs @@ -0,0 +1,60 @@ +using OpenQA.Selenium; +using OpenQA.Selenium.Chrome; +using System.IO; +using System.Reflection; +using Xunit; + +namespace SeleniumTests +{ + public class ChromeDriverTests + { + private ChromeDriver _driver; + private const string _url = "https://localhost:44315/"; + + public ChromeDriverTests() + { + ChromeOptions options = new ChromeOptions(); + options.AddArguments("headless"); + options.AddArguments("no-sandbox"); + _driver = new ChromeDriver(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), + options); + } + + [Fact] + public void HomePageHasCatalogItem() + { + NavigateToHomeAndClickFirstCatalogItemButton(); + + Assert.Equal($"{_url}Basket", _driver.Url); + } + + [Fact] + public void AddItemToCartIncrementsCartIconCount() + { + NavigateToHomeAndClickFirstCatalogItemButton(); + + var cartIcon = _driver.FindElement(By.ClassName("esh-basketstatus-badge")); + + int itemCount = int.Parse(cartIcon.Text); + Assert.Equal(1, itemCount); + } + + private void NavigateToHomeAndClickFirstCatalogItemButton() + { + _driver.Navigate().GoToUrl(_url); + var button = _driver.FindElement(By.ClassName("esh-catalog-button")); + button.Click(); + } + } +} + + + +/* + * + * //var jsToBeExecuted = $"window.scroll(0, {link.Location.Y});"; + //((IJavaScriptExecutor)driver).ExecuteScript(jsToBeExecuted); + //var wait = new WebDriverWait(driver, TimeSpan.FromMinutes(1)); + //var clickableElement = wait.Until(ExpectedConditions.ElementToBeClickable(By.PartialLinkText("TFS Test API"))); + //clickableElement.Click(); +*/ diff --git a/tests/SeleniumTests/SeleniumTests.csproj b/tests/SeleniumTests/SeleniumTests.csproj new file mode 100644 index 0000000..8742038 --- /dev/null +++ b/tests/SeleniumTests/SeleniumTests.csproj @@ -0,0 +1,20 @@ + + + + netcoreapp3.0 + + false + + + + + + + + + + + + + +