diff --git a/BTCPayServer.Tests/Dockerfile b/BTCPayServer.Tests/Dockerfile index aadeef9bc..c473f5211 100644 --- a/BTCPayServer.Tests/Dockerfile +++ b/BTCPayServer.Tests/Dockerfile @@ -8,7 +8,17 @@ WORKDIR /source COPY BTCPayServer/BTCPayServer.csproj BTCPayServer/BTCPayServer.csproj COPY BTCPayServer.Tests/BTCPayServer.Tests.csproj BTCPayServer.Tests/BTCPayServer.Tests.csproj RUN dotnet restore BTCPayServer.Tests/BTCPayServer.Tests.csproj -RUN apk add chromium-chromedriver + +ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT false + +ENV LC_ALL en_US.UTF-8 +ENV LANG en_US.UTF-8 + +RUN apk add --no-cache chromium chromium-chromedriver icu-libs + +ENV SCREEN_HEIGHT 600 \ + SCREEN_WIDTH 1200 + COPY . . RUN dotnet build WORKDIR /source/BTCPayServer.Tests diff --git a/BTCPayServer.Tests/Extensions.cs b/BTCPayServer.Tests/Extensions.cs index 33e436d8d..508719434 100644 --- a/BTCPayServer.Tests/Extensions.cs +++ b/BTCPayServer.Tests/Extensions.cs @@ -11,6 +11,19 @@ namespace BTCPayServer.Tests { public static class Extensions { + public static void ScrollTo(this IWebDriver driver, By by) + { + var element = driver.FindElement(by); + ((IJavaScriptExecutor)driver).ExecuteScript($"window.scrollBy({element.Location.X},{element.Location.Y});"); + } + /// + /// Sometimes the chrome driver is fucked up and we need some magic to click on the element. + /// + /// + public static void ForceClick(this IWebElement element) + { + element.SendKeys(Keys.Return); + } public static void AssertNoError(this IWebDriver driver) { try diff --git a/BTCPayServer.Tests/SeleniumTester.cs b/BTCPayServer.Tests/SeleniumTester.cs index 307fda075..223575cea 100644 --- a/BTCPayServer.Tests/SeleniumTester.cs +++ b/BTCPayServer.Tests/SeleniumTester.cs @@ -33,11 +33,16 @@ namespace BTCPayServer.Tests ChromeOptions options = new ChromeOptions(); options.AddArguments("headless"); // Comment to view browser options.AddArguments("window-size=1200x600"); // Comment to view browser - - Driver = new ChromeDriver(Directory.GetCurrentDirectory(), options); + options.AddArgument("shm-size=2g"); + if (Server.PayTester.InContainer) + { + options.AddArgument("no-sandbox"); + } + Driver = new ChromeDriver(Server.PayTester.InContainer ? "/usr/bin" : Directory.GetCurrentDirectory(), options); Logs.Tester.LogInformation("Selenium: Using chrome driver"); Logs.Tester.LogInformation("Selenium: Browsing to " + Server.PayTester.ServerUri); - + Logs.Tester.LogInformation($"Selenium: Resolution {Driver.Manage().Window.Size}"); + Driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10); Driver.Navigate().GoToUrl(Server.PayTester.ServerUri); Driver.AssertNoError(); } @@ -68,11 +73,11 @@ namespace BTCPayServer.Tests public void AddDerivationScheme() { - Driver.FindElement(By.Id("ModifyBTC")).Click(); + Driver.FindElement(By.Id("ModifyBTC")).ForceClick(); Driver.FindElement(By.Id("DerivationScheme")).SendKeys("xpub661MyMwAqRbcGABgHMUXDzPzH1tU7eZaAaJQXhDXsSxsqyQzQeU6kznNfSuAyqAK9UaWSaZaMFdNiY5BCF4zBPAzSnwfUAwUhwttuAKwfRX-[legacy]"); - Driver.FindElement(By.Id("Continue")).Click(); - Driver.FindElement(By.Id("Confirm")).Click(); - Driver.FindElement(By.Id("Save")).Click(); + Driver.FindElement(By.Id("Continue")).ForceClick(); + Driver.FindElement(By.Id("Confirm")).ForceClick(); + Driver.FindElement(By.Id("Save")).ForceClick(); return; } diff --git a/BTCPayServer.Tests/SeleniumTests.cs b/BTCPayServer.Tests/SeleniumTests.cs index c60ec4965..27aa6074e 100644 --- a/BTCPayServer.Tests/SeleniumTests.cs +++ b/BTCPayServer.Tests/SeleniumTests.cs @@ -125,7 +125,7 @@ namespace BTCPayServer.Tests s.Driver.FindElement(By.CssSelector("select#SelectedStore.form-control")).SendKeys(store + Keys.Enter); s.Driver.FindElement(By.Id("Create")).Click(); s.Driver.FindElement(By.CssSelector("input#EnableShoppingCart.form-check")).Click(); - s.Driver.FindElement(By.Id("SaveSettings")).Click(); + s.Driver.FindElement(By.Id("SaveSettings")).ForceClick(); Assert.True(s.Driver.PageSource.Contains("App updated"), "Unable to create PoS"); s.Driver.Quit(); } @@ -152,7 +152,7 @@ namespace BTCPayServer.Tests s.Driver.FindElement(By.Id("TargetCurrency")).SendKeys("JPY"); s.Driver.FindElement(By.Id("TargetAmount")).SendKeys("700"); s.Driver.FindElement(By.Id("SaveSettings")).Submit(); - s.Driver.FindElement(By.Id("ViewApp")).Click(); + s.Driver.FindElement(By.Id("ViewApp")).ForceClick(); s.Driver.SwitchTo().Window(s.Driver.WindowHandles.Last()); Assert.True(s.Driver.PageSource.Contains("Currently Active!"), "Unable to create CF"); s.Driver.Quit(); diff --git a/BTCPayServer.Tests/docker-compose.yml b/BTCPayServer.Tests/docker-compose.yml index b6ab1ba9c..d4c7b2c18 100644 --- a/BTCPayServer.Tests/docker-compose.yml +++ b/BTCPayServer.Tests/docker-compose.yml @@ -30,7 +30,6 @@ services: - "80" links: - dev - - selenium extra_hosts: - "tests:127.0.0.1" volumes: