Merge pull request #2293 from dennisreimann/flaky-selenium

Tame flaky Selenium tests
This commit is contained in:
Andrew Camilleri 2021-02-18 09:39:28 +01:00 committed by GitHub
commit b30aa968b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 16 deletions

View file

@ -17,6 +17,7 @@ using Microsoft.Extensions.Configuration;
using NBitcoin;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.Extensions;
using Xunit;
namespace BTCPayServer.Tests
@ -47,9 +48,7 @@ namespace BTCPayServer.Tests
var runInBrowser = config["RunSeleniumInBrowser"] == "true";
// Reset this using `dotnet user-secrets remove RunSeleniumInBrowser`
var chromeDriverPath = config["ChromeDriverDirectory"] ??
(Server.PayTester.InContainer ? "/usr/bin" : Directory.GetCurrentDirectory());
var chromeDriverPath = config["ChromeDriverDirectory"] ?? (Server.PayTester.InContainer ? "/usr/bin" : Directory.GetCurrentDirectory());
var options = new ChromeOptions();
if (Server.PayTester.InContainer)
@ -149,18 +148,13 @@ namespace BTCPayServer.Tests
Driver.FindElement(By.Id("ScriptPubKeyType")).Click();
Driver.FindElement(By.CssSelector($"#ScriptPubKeyType option[value={format}]")).Click();
Driver.FindElement(By.Id("AdvancedSettingsButton")).Click();
Driver.SetCheckbox(By.Id("ImportKeysToRPC"), importkeys);
Driver.FindElement(By.Id("AdvancedSettingsButton")).Click(); // close again
try
{
Driver.FindElement(By.Id("Continue")).Click();
}
catch (ElementClickInterceptedException)
{
Driver.WaitForAndClick(By.Id("Continue"));
}
// Open advanced settings via JS, because if we click the link it triggers the toggle animation.
// This leads to Selenium trying to click the button while it is moving resulting in an error.
Driver.ExecuteJavaScript("document.getElementById('AdvancedSettings').classList.add('show')");
Driver.SetCheckbox(By.Id("ImportKeysToRPC"), importkeys);
Driver.FindElement(By.Id("Continue")).Click();
// Seed backup page
FindAlertMessage();

View file

@ -58,10 +58,10 @@
}
<div class="mb-4">
<button class="btn btn-link px-0" type="button" id="AdvancedSettingsButton" data-toggle="collapse" data-target="#advanced-settings" aria-expanded="false" aria-controls="advanced-settings">
<button class="btn btn-link px-0" type="button" id="AdvancedSettingsButton" data-toggle="collapse" data-target="#AdvancedSettings" aria-expanded="false" aria-controls="advanced-settings">
Advanced settings
</button>
<div id="advanced-settings" class="collapse @(string.IsNullOrEmpty(Model.Passphrase) && !Model.ImportKeysToRPC ? "" : "show")">
<div id="AdvancedSettings" class="collapse @(string.IsNullOrEmpty(Model.Passphrase) && !Model.ImportKeysToRPC ? "" : "show")">
<div class="pt-3 pb-1">
@if (isImport) // hide account option when creating a wallet
{