2019-09-10 10:03:24 +02:00
|
|
|
using System;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Net.Http;
|
2019-10-06 16:13:42 +02:00
|
|
|
using System.Threading;
|
2019-09-10 10:03:24 +02:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
using BTCPayServer.Lightning;
|
2020-02-19 09:39:14 +01:00
|
|
|
using BTCPayServer.Payments;
|
2019-09-10 10:03:24 +02:00
|
|
|
using BTCPayServer.Tests.Logging;
|
|
|
|
using BTCPayServer.Views.Stores;
|
2020-02-19 09:39:14 +01:00
|
|
|
using NBitcoin;
|
2019-09-10 10:03:24 +02:00
|
|
|
using NBitpayClient;
|
|
|
|
using OpenQA.Selenium;
|
|
|
|
using OpenQA.Selenium.Interactions;
|
|
|
|
using OpenQA.Selenium.Support.UI;
|
|
|
|
using Xunit;
|
|
|
|
using Xunit.Abstractions;
|
|
|
|
|
|
|
|
namespace BTCPayServer.Tests
|
|
|
|
{
|
|
|
|
[Trait("Selenium", "Selenium")]
|
|
|
|
public class CheckoutUITests
|
|
|
|
{
|
2019-11-06 06:31:45 +01:00
|
|
|
public const int TestTimeout = TestUtils.TestTimeout;
|
2019-09-11 09:22:41 +02:00
|
|
|
public CheckoutUITests(ITestOutputHelper helper)
|
2019-09-10 10:03:24 +02:00
|
|
|
{
|
2019-10-20 09:47:48 +02:00
|
|
|
Logs.Tester = new XUnitLog(helper) { Name = "Tests" };
|
2019-09-10 10:03:24 +02:00
|
|
|
Logs.LogProvider = new XUnitLogProvider(helper);
|
|
|
|
}
|
2019-09-11 09:22:41 +02:00
|
|
|
|
2019-10-12 13:35:30 +02:00
|
|
|
[Fact(Timeout = TestTimeout)]
|
2019-09-10 10:03:24 +02:00
|
|
|
public async Task CanHandleRefundEmailForm()
|
|
|
|
{
|
|
|
|
|
2019-09-11 09:22:41 +02:00
|
|
|
using (var s = SeleniumTester.Create())
|
|
|
|
{
|
2019-10-07 09:04:25 +02:00
|
|
|
await s.StartAsync();
|
2019-11-06 06:31:45 +01:00
|
|
|
s.GoToRegister();
|
2019-09-11 09:22:41 +02:00
|
|
|
s.RegisterNewUser();
|
|
|
|
var store = s.CreateNewStore();
|
|
|
|
s.AddDerivationScheme("BTC");
|
2019-10-20 09:45:40 +02:00
|
|
|
s.GoToStore(store.storeId, StoreNavPages.Checkout);
|
|
|
|
s.Driver.FindElement(By.Id("RequiresRefundEmail")).Click();
|
|
|
|
s.Driver.FindElement(By.Name("command")).ForceClick();
|
2019-09-11 09:22:41 +02:00
|
|
|
|
2019-10-20 09:47:48 +02:00
|
|
|
var emailAlreadyThereInvoiceId = s.CreateInvoice(store.storeName, 100, "USD", "a@g.com");
|
2019-09-11 09:22:41 +02:00
|
|
|
s.GoToInvoiceCheckout(emailAlreadyThereInvoiceId);
|
|
|
|
s.Driver.AssertElementNotFound(By.Id("emailAddressFormInput"));
|
|
|
|
s.GoToHome();
|
|
|
|
var invoiceId = s.CreateInvoice(store.storeName);
|
2019-10-12 13:35:30 +02:00
|
|
|
s.Driver.FindElement(By.ClassName("invoice-details-link")).Click();
|
|
|
|
s.Driver.AssertNoError();
|
|
|
|
s.Driver.Navigate().Back();
|
|
|
|
s.Driver.FindElement(By.ClassName("invoice-checkout-link")).Click();
|
|
|
|
Assert.NotEmpty(s.Driver.FindElements(By.Id("checkoutCtrl")));
|
|
|
|
|
2019-09-11 09:22:41 +02:00
|
|
|
Assert.True(s.Driver.FindElement(By.Id("emailAddressFormInput")).Displayed);
|
|
|
|
s.Driver.FindElement(By.Id("emailAddressFormInput")).SendKeys("xxx");
|
|
|
|
s.Driver.FindElement(By.Id("emailAddressForm")).FindElement(By.CssSelector("button.action-button"))
|
|
|
|
.Click();
|
2019-09-12 11:28:11 +02:00
|
|
|
var formInput = s.Driver.FindElement(By.Id("emailAddressFormInput"));
|
2019-10-20 09:47:48 +02:00
|
|
|
|
2019-09-12 11:28:11 +02:00
|
|
|
Assert.True(formInput.Displayed);
|
|
|
|
Assert.Contains("form-input-invalid", formInput.GetAttribute("class"));
|
|
|
|
formInput = s.Driver.FindElement(By.Id("emailAddressFormInput"));
|
|
|
|
formInput.SendKeys("@g.com");
|
2019-10-12 13:35:30 +02:00
|
|
|
var actionButton = s.Driver.FindElement(By.Id("emailAddressForm")).FindElement(By.CssSelector("button.action-button"));
|
|
|
|
actionButton.Click();
|
2019-10-20 09:47:48 +02:00
|
|
|
try // Sometimes the click only take the focus, without actually really clicking on it...
|
|
|
|
{
|
|
|
|
actionButton.Click();
|
|
|
|
}
|
|
|
|
catch { }
|
2019-09-11 09:22:41 +02:00
|
|
|
|
2020-03-02 05:38:40 +01:00
|
|
|
s.Driver.AssertElementNotFound(By.Id("emailAddressFormInput"));
|
2019-10-12 13:35:30 +02:00
|
|
|
s.Driver.Navigate().Refresh();
|
2019-09-11 09:22:41 +02:00
|
|
|
s.Driver.AssertElementNotFound(By.Id("emailAddressFormInput"));
|
|
|
|
}
|
2019-09-10 10:03:24 +02:00
|
|
|
}
|
|
|
|
|
2019-10-06 15:49:28 +02:00
|
|
|
[Fact(Timeout = TestTimeout)]
|
2019-09-10 10:03:24 +02:00
|
|
|
public async Task CanUseLanguageDropdown()
|
|
|
|
{
|
2019-09-11 09:22:41 +02:00
|
|
|
using (var s = SeleniumTester.Create())
|
|
|
|
{
|
2019-10-07 09:04:25 +02:00
|
|
|
await s.StartAsync();
|
2019-11-06 06:31:45 +01:00
|
|
|
s.GoToRegister();
|
2019-09-11 09:22:41 +02:00
|
|
|
s.RegisterNewUser();
|
|
|
|
var store = s.CreateNewStore();
|
|
|
|
s.AddDerivationScheme("BTC");
|
|
|
|
|
|
|
|
var invoiceId = s.CreateInvoice(store.storeName);
|
|
|
|
s.GoToInvoiceCheckout(invoiceId);
|
|
|
|
Assert.True(s.Driver.FindElement(By.Id("DefaultLang")).FindElements(By.TagName("option")).Count > 1);
|
|
|
|
var payWithTextEnglish = s.Driver.FindElement(By.Id("pay-with-text")).Text;
|
2020-03-02 05:38:40 +01:00
|
|
|
|
2019-09-11 09:22:41 +02:00
|
|
|
var prettyDropdown = s.Driver.FindElement(By.Id("prettydropdown-DefaultLang"));
|
|
|
|
prettyDropdown.Click();
|
|
|
|
await Task.Delay(200);
|
|
|
|
prettyDropdown.FindElement(By.CssSelector("[data-value=\"da-DK\"]")).Click();
|
|
|
|
await Task.Delay(1000);
|
|
|
|
Assert.NotEqual(payWithTextEnglish, s.Driver.FindElement(By.Id("pay-with-text")).Text);
|
|
|
|
s.Driver.Navigate().GoToUrl(s.Driver.Url + "?lang=da-DK");
|
2020-03-02 05:38:40 +01:00
|
|
|
|
2019-09-11 09:22:41 +02:00
|
|
|
Assert.NotEqual(payWithTextEnglish, s.Driver.FindElement(By.Id("pay-with-text")).Text);
|
2020-03-02 05:38:40 +01:00
|
|
|
|
2019-09-11 09:22:41 +02:00
|
|
|
s.Driver.Quit();
|
|
|
|
}
|
2019-09-10 10:03:24 +02:00
|
|
|
}
|
2020-03-02 05:38:40 +01:00
|
|
|
|
2019-10-06 15:49:28 +02:00
|
|
|
[Fact(Timeout = TestTimeout)]
|
2019-12-24 10:11:21 +01:00
|
|
|
[Trait("Altcoins", "Altcoins")]
|
|
|
|
[Trait("Lightning", "Lightning")]
|
2019-10-07 09:04:25 +02:00
|
|
|
public async Task CanUsePaymentMethodDropdown()
|
2019-09-10 10:03:24 +02:00
|
|
|
{
|
2019-09-11 09:22:41 +02:00
|
|
|
using (var s = SeleniumTester.Create())
|
|
|
|
{
|
2019-12-24 10:11:21 +01:00
|
|
|
s.Server.ActivateLTC();
|
|
|
|
s.Server.ActivateLightning();
|
2019-10-07 09:04:25 +02:00
|
|
|
await s.StartAsync();
|
2019-11-06 06:31:45 +01:00
|
|
|
s.GoToRegister();
|
2019-09-11 09:22:41 +02:00
|
|
|
s.RegisterNewUser();
|
|
|
|
var store = s.CreateNewStore();
|
|
|
|
s.AddDerivationScheme("BTC");
|
2020-03-02 05:38:40 +01:00
|
|
|
|
2019-09-11 09:22:41 +02:00
|
|
|
//check that there is no dropdown since only one payment method is set
|
|
|
|
var invoiceId = s.CreateInvoice(store.storeName, 10, "USD", "a@g.com");
|
|
|
|
s.GoToInvoiceCheckout(invoiceId);
|
|
|
|
s.Driver.FindElement(By.ClassName("payment__currencies_noborder"));
|
|
|
|
s.GoToHome();
|
|
|
|
s.GoToStore(store.storeId);
|
|
|
|
s.AddDerivationScheme("LTC");
|
2020-03-02 05:38:40 +01:00
|
|
|
s.AddLightningNode("BTC", LightningConnectionType.CLightning);
|
2019-09-11 09:22:41 +02:00
|
|
|
//there should be three now
|
|
|
|
invoiceId = s.CreateInvoice(store.storeName, 10, "USD", "a@g.com");
|
|
|
|
s.GoToInvoiceCheckout(invoiceId);
|
2020-03-02 05:38:40 +01:00
|
|
|
var currencyDropdownButton = s.Driver.WaitForElement(By.ClassName("payment__currencies"));
|
2019-09-11 09:22:41 +02:00
|
|
|
Assert.Contains("BTC", currencyDropdownButton.Text);
|
|
|
|
currencyDropdownButton.Click();
|
2020-03-02 05:38:40 +01:00
|
|
|
|
2019-10-06 16:13:42 +02:00
|
|
|
var elements = s.Driver.FindElement(By.ClassName("vex-content")).FindElements(By.ClassName("vexmenuitem"));
|
2019-09-11 09:22:41 +02:00
|
|
|
Assert.Equal(3, elements.Count);
|
|
|
|
elements.Single(element => element.Text.Contains("LTC")).Click();
|
2020-03-02 05:38:40 +01:00
|
|
|
currencyDropdownButton = s.Driver.WaitForElement(By.ClassName("payment__currencies"));
|
2019-09-11 09:22:41 +02:00
|
|
|
Assert.Contains("LTC", currencyDropdownButton.Text);
|
2019-10-06 16:13:42 +02:00
|
|
|
currencyDropdownButton.Click();
|
|
|
|
|
|
|
|
elements = s.Driver.FindElement(By.ClassName("vex-content")).FindElements(By.ClassName("vexmenuitem"));
|
2019-09-11 09:22:41 +02:00
|
|
|
elements.Single(element => element.Text.Contains("Lightning")).Click();
|
2019-10-06 16:13:42 +02:00
|
|
|
|
2020-03-02 05:38:40 +01:00
|
|
|
currencyDropdownButton = s.Driver.WaitForElement(By.ClassName("payment__currencies"));
|
2019-09-11 09:22:41 +02:00
|
|
|
Assert.Contains("Lightning", currencyDropdownButton.Text);
|
2020-03-02 05:38:40 +01:00
|
|
|
|
2019-09-11 09:22:41 +02:00
|
|
|
s.Driver.Quit();
|
|
|
|
}
|
2019-09-10 10:03:24 +02:00
|
|
|
}
|
2020-03-02 05:38:40 +01:00
|
|
|
|
2019-10-06 15:49:28 +02:00
|
|
|
[Fact(Timeout = TestTimeout)]
|
2019-12-24 10:11:21 +01:00
|
|
|
[Trait("Lightning", "Lightning")]
|
2019-10-07 09:04:25 +02:00
|
|
|
public async Task CanUseLightningSatsFeature()
|
2019-09-10 10:03:24 +02:00
|
|
|
{
|
2019-09-11 09:22:41 +02:00
|
|
|
using (var s = SeleniumTester.Create())
|
|
|
|
{
|
2019-12-24 10:11:21 +01:00
|
|
|
s.Server.ActivateLightning();
|
2019-10-07 09:04:25 +02:00
|
|
|
await s.StartAsync();
|
2019-11-06 06:31:45 +01:00
|
|
|
s.GoToRegister();
|
2019-09-11 09:22:41 +02:00
|
|
|
s.RegisterNewUser();
|
|
|
|
var store = s.CreateNewStore();
|
|
|
|
s.AddInternalLightningNode("BTC");
|
|
|
|
s.GoToStore(store.storeId, StoreNavPages.Checkout);
|
|
|
|
s.SetCheckbox(s, "LightningAmountInSatoshi", true);
|
|
|
|
var command = s.Driver.FindElement(By.Name("command"));
|
2020-03-02 05:38:40 +01:00
|
|
|
|
2019-09-11 09:22:41 +02:00
|
|
|
command.ForceClick();
|
|
|
|
var invoiceId = s.CreateInvoice(store.storeName, 10, "USD", "a@g.com");
|
|
|
|
s.GoToInvoiceCheckout(invoiceId);
|
|
|
|
Assert.Contains("Sats", s.Driver.FindElement(By.ClassName("payment__currencies_noborder")).Text);
|
2020-03-02 05:38:40 +01:00
|
|
|
|
2019-09-11 09:22:41 +02:00
|
|
|
}
|
2019-09-10 10:03:24 +02:00
|
|
|
}
|
2020-02-19 09:39:14 +01:00
|
|
|
|
|
|
|
[Fact(Timeout = TestTimeout)]
|
|
|
|
public async Task CanUseJSModal()
|
|
|
|
{
|
|
|
|
using (var s = SeleniumTester.Create())
|
|
|
|
{
|
|
|
|
await s.StartAsync();
|
|
|
|
s.GoToRegister();
|
|
|
|
s.RegisterNewUser();
|
|
|
|
var store = s.CreateNewStore();
|
|
|
|
s.GoToStore(store.storeId);
|
|
|
|
s.AddDerivationScheme();
|
|
|
|
var invoiceId = s.CreateInvoice(store.storeId, 0.001m, "BTC", "a@x.com");
|
|
|
|
var invoice = await s.Server.PayTester.InvoiceRepository.GetInvoice(invoiceId);
|
|
|
|
s.Driver.Navigate()
|
|
|
|
.GoToUrl(new Uri(s.Server.PayTester.ServerUri, $"tests/index.html?invoice={invoiceId}"));
|
|
|
|
TestUtils.Eventually(() =>
|
|
|
|
{
|
|
|
|
Assert.True(s.Driver.FindElement(By.Name("btcpay")).Displayed);
|
|
|
|
});
|
|
|
|
await s.Server.ExplorerNode.SendToAddressAsync(BitcoinAddress.Create(invoice
|
|
|
|
.GetPaymentMethod(new PaymentMethodId("BTC", PaymentTypes.BTCLike))
|
|
|
|
.GetPaymentMethodDetails().GetPaymentDestination(), Network.RegTest),
|
|
|
|
new Money(0.001m, MoneyUnit.BTC));
|
|
|
|
|
|
|
|
IWebElement closebutton = null;
|
|
|
|
TestUtils.Eventually(() =>
|
|
|
|
{
|
2020-03-11 16:51:33 +01:00
|
|
|
var frameElement = s.Driver.FindElement(By.Name("btcpay"));
|
|
|
|
var iframe = s.Driver.SwitchTo().Frame(frameElement);
|
2020-02-19 09:39:14 +01:00
|
|
|
closebutton = iframe.FindElement(By.ClassName("close-action"));
|
|
|
|
Assert.True(closebutton.Displayed);
|
|
|
|
});
|
|
|
|
closebutton.Click();
|
|
|
|
s.Driver.AssertElementNotFound(By.Name("btcpay"));
|
|
|
|
Assert.Equal(s.Driver.Url,
|
|
|
|
new Uri(s.Server.PayTester.ServerUri, $"tests/index.html?invoice={invoiceId}").ToString());
|
|
|
|
}
|
|
|
|
}
|
2019-09-10 10:03:24 +02:00
|
|
|
}
|
2020-03-02 05:38:40 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2019-09-10 10:03:24 +02:00
|
|
|
}
|