mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-22 14:22:40 +01:00
Fixing Selenium tests failing because of dynamic hidden elements
This commit is contained in:
parent
4f5f52b937
commit
304caaaf1d
1 changed files with 41 additions and 17 deletions
|
@ -129,27 +129,25 @@ namespace BTCPayServer.Tests
|
||||||
s.GoToHome();
|
s.GoToHome();
|
||||||
s.GoToStore(store.storeId);
|
s.GoToStore(store.storeId);
|
||||||
s.AddDerivationScheme("LTC");
|
s.AddDerivationScheme("LTC");
|
||||||
s.AddLightningNode("BTC",LightningConnectionType.CLightning);
|
s.AddLightningNode("BTC", LightningConnectionType.CLightning);
|
||||||
//there should be three now
|
//there should be three now
|
||||||
invoiceId = s.CreateInvoice(store.storeName, 10, "USD", "a@g.com");
|
invoiceId = s.CreateInvoice(store.storeName, 10, "USD", "a@g.com");
|
||||||
s.GoToInvoiceCheckout(invoiceId);
|
s.GoToInvoiceCheckout(invoiceId);
|
||||||
var currencyDropdownButton = s.Driver.FindElement(By.ClassName("payment__currencies"));
|
var currencyDropdownButton = s.Driver.WaitForElement(By.ClassName("payment__currencies"));
|
||||||
Assert.Contains("BTC", currencyDropdownButton.Text);
|
Assert.Contains("BTC", currencyDropdownButton.Text);
|
||||||
currencyDropdownButton.Click();
|
currencyDropdownButton.Click();
|
||||||
|
|
||||||
var elements = s.Driver.FindElement(By.ClassName("vex-content")).FindElements(By.ClassName("vexmenuitem"));
|
var elements = s.Driver.FindElement(By.ClassName("vex-content")).FindElements(By.ClassName("vexmenuitem"));
|
||||||
Assert.Equal(3, elements.Count);
|
Assert.Equal(3, elements.Count);
|
||||||
elements.Single(element => element.Text.Contains("LTC")).Click();
|
elements.Single(element => element.Text.Contains("LTC")).Click();
|
||||||
Thread.Sleep(1000);
|
currencyDropdownButton = s.Driver.WaitForElement(By.ClassName("payment__currencies"));
|
||||||
currencyDropdownButton = s.Driver.FindElement(By.ClassName("payment__currencies"));
|
|
||||||
Assert.Contains("LTC", currencyDropdownButton.Text);
|
Assert.Contains("LTC", currencyDropdownButton.Text);
|
||||||
currencyDropdownButton.Click();
|
currencyDropdownButton.Click();
|
||||||
|
|
||||||
elements = s.Driver.FindElement(By.ClassName("vex-content")).FindElements(By.ClassName("vexmenuitem"));
|
elements = s.Driver.FindElement(By.ClassName("vex-content")).FindElements(By.ClassName("vexmenuitem"));
|
||||||
elements.Single(element => element.Text.Contains("Lightning")).Click();
|
elements.Single(element => element.Text.Contains("Lightning")).Click();
|
||||||
Thread.Sleep(1000);
|
|
||||||
currencyDropdownButton = s.Driver.FindElement(By.ClassName("payment__currencies"));
|
|
||||||
|
|
||||||
|
currencyDropdownButton = s.Driver.WaitForElement(By.ClassName("payment__currencies"));
|
||||||
Assert.Contains("Lightning", currencyDropdownButton.Text);
|
Assert.Contains("Lightning", currencyDropdownButton.Text);
|
||||||
|
|
||||||
s.Driver.Quit();
|
s.Driver.Quit();
|
||||||
|
@ -218,4 +216,30 @@ namespace BTCPayServer.Tests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class SeleniumExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Utility method to wait until timeout for element to be present (optionally displayed)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="context">Wait context</param>
|
||||||
|
/// <param name="by">How we search for element</param>
|
||||||
|
/// <param name="displayed">Flag to wait for element to be displayed or just present</param>
|
||||||
|
/// <param name="timeout">How long to wait for element to be present/displayed</param>
|
||||||
|
/// <returns>Element we were waiting for</returns>
|
||||||
|
public static IWebElement WaitForElement(this IWebDriver context, By by, bool displayed = true, uint timeout = 3)
|
||||||
|
{
|
||||||
|
var wait = new DefaultWait<IWebDriver>(context);
|
||||||
|
wait.Timeout = TimeSpan.FromSeconds(timeout);
|
||||||
|
wait.IgnoreExceptionTypes(typeof(NoSuchElementException));
|
||||||
|
return wait.Until(ctx =>
|
||||||
|
{
|
||||||
|
var elem = ctx.FindElement(by);
|
||||||
|
if (displayed && !elem.Displayed)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return elem;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue