mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 22:44:29 +01:00
Revert "Share same browser for all selenium tests"
This reverts commit 2ce0749bb6.
This commit is contained in:
@@ -19,16 +19,12 @@ using OpenQA.Selenium;
|
|||||||
|
|
||||||
namespace BTCPayServer.Tests
|
namespace BTCPayServer.Tests
|
||||||
{
|
{
|
||||||
[Collection("Selenium collection")]
|
|
||||||
public class AuthenticationTests
|
public class AuthenticationTests
|
||||||
{
|
{
|
||||||
public SeleniumTester SeleniumTester { get; }
|
public AuthenticationTests(ITestOutputHelper helper)
|
||||||
|
|
||||||
public AuthenticationTests(ITestOutputHelper helper, SeleniumTester seleniumTester)
|
|
||||||
{
|
{
|
||||||
Logs.Tester = new XUnitLog(helper) {Name = "Tests"};
|
Logs.Tester = new XUnitLog(helper) {Name = "Tests"};
|
||||||
Logs.LogProvider = new XUnitLogProvider(helper);
|
Logs.LogProvider = new XUnitLogProvider(helper);
|
||||||
SeleniumTester = seleniumTester;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -97,7 +93,10 @@ namespace BTCPayServer.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public async Task CanUseImplicitFlow()
|
public async Task CanUseImplicitFlow()
|
||||||
{
|
{
|
||||||
var tester = SeleniumTester.Server;
|
using (var s = SeleniumTester.Create())
|
||||||
|
{
|
||||||
|
s.Start();
|
||||||
|
var tester = s.Server;
|
||||||
|
|
||||||
var user = tester.NewAccount();
|
var user = tester.NewAccount();
|
||||||
user.GrantAccess();
|
user.GrantAccess();
|
||||||
@@ -113,30 +112,31 @@ namespace BTCPayServer.Tests
|
|||||||
});
|
});
|
||||||
var implicitAuthorizeUrl = new Uri(tester.PayTester.ServerUri,
|
var implicitAuthorizeUrl = new Uri(tester.PayTester.ServerUri,
|
||||||
$"connect/authorize?response_type=token&client_id={id}&redirect_uri={redirecturi.AbsoluteUri}&scope=openid&nonce={Guid.NewGuid().ToString()}");
|
$"connect/authorize?response_type=token&client_id={id}&redirect_uri={redirecturi.AbsoluteUri}&scope=openid&nonce={Guid.NewGuid().ToString()}");
|
||||||
SeleniumTester.Driver.Navigate().GoToUrl(implicitAuthorizeUrl);
|
s.Driver.Navigate().GoToUrl(implicitAuthorizeUrl);
|
||||||
SeleniumTester.Login(user.RegisterDetails.Email, user.RegisterDetails.Password);
|
s.Login(user.RegisterDetails.Email, user.RegisterDetails.Password);
|
||||||
SeleniumTester.Driver.FindElement(By.Id("consent-yes")).Click();
|
s.Driver.FindElement(By.Id("consent-yes")).Click();
|
||||||
var url = SeleniumTester.Driver.Url;
|
var url = s.Driver.Url;
|
||||||
var results = url.Split("#").Last().Split("&")
|
var results = url.Split("#").Last().Split("&")
|
||||||
.ToDictionary(s1 => s1.Split("=")[0], s1 => s1.Split("=")[1]);
|
.ToDictionary(s1 => s1.Split("=")[0], s1 => s1.Split("=")[1]);
|
||||||
await TestApiAgainstAccessToken(results["access_token"], tester, user);
|
await TestApiAgainstAccessToken(results["access_token"], tester, user);
|
||||||
//in Implicit mode, you renew your token by hitting the same endpoint but adding prompt=none. If you are still logged in on the site, you will receive a fresh token.
|
//in Implicit mode, you renew your token by hitting the same endpoint but adding prompt=none. If you are still logged in on the site, you will receive a fresh token.
|
||||||
var implicitAuthorizeUrlSilentModel = new Uri($"{implicitAuthorizeUrl.OriginalString}&prompt=none");
|
var implicitAuthorizeUrlSilentModel = new Uri($"{implicitAuthorizeUrl.OriginalString}&prompt=none");
|
||||||
SeleniumTester.Driver.Navigate().GoToUrl(implicitAuthorizeUrlSilentModel);
|
s.Driver.Navigate().GoToUrl(implicitAuthorizeUrlSilentModel);
|
||||||
url = SeleniumTester.Driver.Url;
|
url = s.Driver.Url;
|
||||||
results = url.Split("#").Last().Split("&").ToDictionary(s1 => s1.Split("=")[0], s1 => s1.Split("=")[1]);
|
results = url.Split("#").Last().Split("&").ToDictionary(s1 => s1.Split("=")[0], s1 => s1.Split("=")[1]);
|
||||||
await TestApiAgainstAccessToken(results["access_token"], tester, user);
|
await TestApiAgainstAccessToken(results["access_token"], tester, user);
|
||||||
|
|
||||||
LogoutFlow(tester, id, SeleniumTester);
|
LogoutFlow(tester, id, s);
|
||||||
|
|
||||||
SeleniumTester.Driver.Navigate().GoToUrl(implicitAuthorizeUrl);
|
s.Driver.Navigate().GoToUrl(implicitAuthorizeUrl);
|
||||||
SeleniumTester.Login(user.RegisterDetails.Email, user.RegisterDetails.Password);
|
s.Login(user.RegisterDetails.Email, user.RegisterDetails.Password);
|
||||||
|
|
||||||
Assert.Throws<NoSuchElementException>(() => SeleniumTester.Driver.FindElement(By.Id("consent-yes")));
|
Assert.Throws<NoSuchElementException>(() => s.Driver.FindElement(By.Id("consent-yes")));
|
||||||
results = url.Split("#").Last().Split("&")
|
results = url.Split("#").Last().Split("&")
|
||||||
.ToDictionary(s1 => s1.Split("=")[0], s1 => s1.Split("=")[1]);
|
.ToDictionary(s1 => s1.Split("=")[0], s1 => s1.Split("=")[1]);
|
||||||
await TestApiAgainstAccessToken(results["access_token"], tester, user);
|
await TestApiAgainstAccessToken(results["access_token"], tester, user);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void LogoutFlow(ServerTester tester, string clientId, SeleniumTester seleniumTester)
|
void LogoutFlow(ServerTester tester, string clientId, SeleniumTester seleniumTester)
|
||||||
{
|
{
|
||||||
@@ -152,7 +152,10 @@ namespace BTCPayServer.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public async Task CanUseCodeFlow()
|
public async Task CanUseCodeFlow()
|
||||||
{
|
{
|
||||||
var tester = SeleniumTester.Server;
|
using (var s = SeleniumTester.Create())
|
||||||
|
{
|
||||||
|
s.Start();
|
||||||
|
var tester = s.Server;
|
||||||
|
|
||||||
var user = tester.NewAccount();
|
var user = tester.NewAccount();
|
||||||
user.GrantAccess();
|
user.GrantAccess();
|
||||||
@@ -173,10 +176,10 @@ namespace BTCPayServer.Tests
|
|||||||
}, secret);
|
}, secret);
|
||||||
var authorizeUrl = new Uri(tester.PayTester.ServerUri,
|
var authorizeUrl = new Uri(tester.PayTester.ServerUri,
|
||||||
$"connect/authorize?response_type=code&client_id={id}&redirect_uri={redirecturi.AbsoluteUri}&scope=openid offline_access&state={Guid.NewGuid().ToString()}");
|
$"connect/authorize?response_type=code&client_id={id}&redirect_uri={redirecturi.AbsoluteUri}&scope=openid offline_access&state={Guid.NewGuid().ToString()}");
|
||||||
SeleniumTester.Driver.Navigate().GoToUrl(authorizeUrl);
|
s.Driver.Navigate().GoToUrl(authorizeUrl);
|
||||||
SeleniumTester.Login(user.RegisterDetails.Email, user.RegisterDetails.Password);
|
s.Login(user.RegisterDetails.Email, user.RegisterDetails.Password);
|
||||||
SeleniumTester.Driver.FindElement(By.Id("consent-yes")).Click();
|
s.Driver.FindElement(By.Id("consent-yes")).Click();
|
||||||
var url = SeleniumTester.Driver.Url;
|
var url = s.Driver.Url;
|
||||||
var results = url.Split("?").Last().Split("&")
|
var results = url.Split("?").Last().Split("&")
|
||||||
.ToDictionary(s1 => s1.Split("=")[0], s1 => s1.Split("=")[1]);
|
.ToDictionary(s1 => s1.Split("=")[0], s1 => s1.Split("=")[1]);
|
||||||
|
|
||||||
@@ -210,15 +213,16 @@ namespace BTCPayServer.Tests
|
|||||||
|
|
||||||
await TestApiAgainstAccessToken(refreshedAccessToken, tester, user);
|
await TestApiAgainstAccessToken(refreshedAccessToken, tester, user);
|
||||||
|
|
||||||
LogoutFlow(tester, id, SeleniumTester);
|
LogoutFlow(tester, id, s);
|
||||||
SeleniumTester.Driver.Navigate().GoToUrl(authorizeUrl);
|
s.Driver.Navigate().GoToUrl(authorizeUrl);
|
||||||
SeleniumTester.Login(user.RegisterDetails.Email, user.RegisterDetails.Password);
|
s.Login(user.RegisterDetails.Email, user.RegisterDetails.Password);
|
||||||
|
|
||||||
Assert.Throws<NoSuchElementException>(() => SeleniumTester.Driver.FindElement(By.Id("consent-yes")));
|
Assert.Throws<NoSuchElementException>(() => s.Driver.FindElement(By.Id("consent-yes")));
|
||||||
results = url.Split("?").Last().Split("&")
|
results = url.Split("?").Last().Split("&")
|
||||||
.ToDictionary(s1 => s1.Split("=")[0], s1 => s1.Split("=")[1]);
|
.ToDictionary(s1 => s1.Split("=")[0], s1 => s1.Split("=")[1]);
|
||||||
Assert.True(results.ContainsKey("code"));
|
Assert.True(results.ContainsKey("code"));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static async Task<string> RefreshAnAccessToken(string refreshToken, HttpClient client, string clientId,
|
private static async Task<string> RefreshAnAccessToken(string refreshToken, HttpClient client, string clientId,
|
||||||
string clientSecret = null)
|
string clientSecret = null)
|
||||||
|
|||||||
@@ -15,140 +15,163 @@ using Xunit.Abstractions;
|
|||||||
namespace BTCPayServer.Tests
|
namespace BTCPayServer.Tests
|
||||||
{
|
{
|
||||||
[Trait("Selenium", "Selenium")]
|
[Trait("Selenium", "Selenium")]
|
||||||
[Collection("Selenium collection")]
|
|
||||||
public class CheckoutUITests
|
public class CheckoutUITests
|
||||||
{
|
{
|
||||||
public SeleniumTester SeleniumTester { get; }
|
public CheckoutUITests(ITestOutputHelper helper)
|
||||||
|
|
||||||
public CheckoutUITests(ITestOutputHelper helper, SeleniumTester seleniumTester)
|
|
||||||
{
|
{
|
||||||
Logs.Tester = new XUnitLog(helper) {Name = "Tests"};
|
Logs.Tester = new XUnitLog(helper) {Name = "Tests"};
|
||||||
Logs.LogProvider = new XUnitLogProvider(helper);
|
Logs.LogProvider = new XUnitLogProvider(helper);
|
||||||
SeleniumTester = seleniumTester;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void CanCreateInvoice()
|
public void CanCreateInvoice()
|
||||||
{
|
{
|
||||||
SeleniumTester.RegisterNewUser();
|
using (var s = SeleniumTester.Create())
|
||||||
var store = SeleniumTester.CreateNewStore().storeName;
|
{
|
||||||
SeleniumTester.AddDerivationScheme();
|
s.Start();
|
||||||
|
s.RegisterNewUser();
|
||||||
|
var store = s.CreateNewStore().storeName;
|
||||||
|
s.AddDerivationScheme();
|
||||||
|
|
||||||
SeleniumTester.CreateInvoice(store);
|
s.CreateInvoice(store);
|
||||||
|
|
||||||
SeleniumTester.Driver.FindElement(By.ClassName("invoice-details-link")).Click();
|
s.Driver.FindElement(By.ClassName("invoice-details-link")).Click();
|
||||||
SeleniumTester.Driver.AssertNoError();
|
s.Driver.AssertNoError();
|
||||||
SeleniumTester.Driver.Navigate().Back();
|
s.Driver.Navigate().Back();
|
||||||
SeleniumTester.Driver.FindElement(By.ClassName("invoice-checkout-link")).Click();
|
s.Driver.FindElement(By.ClassName("invoice-checkout-link")).Click();
|
||||||
Assert.NotEmpty(SeleniumTester.Driver.FindElements(By.Id("checkoutCtrl")));
|
Assert.NotEmpty(s.Driver.FindElements(By.Id("checkoutCtrl")));
|
||||||
|
s.Driver.Quit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task CanHandleRefundEmailForm()
|
public async Task CanHandleRefundEmailForm()
|
||||||
{
|
{
|
||||||
SeleniumTester.RegisterNewUser();
|
|
||||||
var store = SeleniumTester.CreateNewStore();
|
|
||||||
SeleniumTester.AddDerivationScheme("BTC");
|
|
||||||
|
|
||||||
var emailAlreadyThereInvoiceId = SeleniumTester.CreateInvoice(store.storeName, 100, "USD", "a@g.com");
|
using (var s = SeleniumTester.Create())
|
||||||
SeleniumTester.GoToInvoiceCheckout(emailAlreadyThereInvoiceId);
|
{
|
||||||
SeleniumTester.Driver.AssertElementNotFound(By.Id("emailAddressFormInput"));
|
s.Start();
|
||||||
SeleniumTester.GoToHome();
|
s.RegisterNewUser();
|
||||||
var invoiceId = SeleniumTester.CreateInvoice(store.storeName);
|
var store = s.CreateNewStore();
|
||||||
SeleniumTester.GoToInvoiceCheckout(invoiceId);
|
s.AddDerivationScheme("BTC");
|
||||||
Assert.True(SeleniumTester.Driver.FindElement(By.Id("emailAddressFormInput")).Displayed);
|
|
||||||
SeleniumTester.Driver.FindElement(By.Id("emailAddressFormInput")).SendKeys("xxx");
|
var emailAlreadyThereInvoiceId =s.CreateInvoice(store.storeName, 100, "USD", "a@g.com");
|
||||||
SeleniumTester.Driver.FindElement(By.Id("emailAddressForm")).FindElement(By.CssSelector("button.action-button"))
|
s.GoToInvoiceCheckout(emailAlreadyThereInvoiceId);
|
||||||
|
s.Driver.AssertElementNotFound(By.Id("emailAddressFormInput"));
|
||||||
|
s.GoToHome();
|
||||||
|
var invoiceId = s.CreateInvoice(store.storeName);
|
||||||
|
s.GoToInvoiceCheckout(invoiceId);
|
||||||
|
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();
|
.Click();
|
||||||
|
|
||||||
Assert.True(SeleniumTester.Driver.FindElement(By.Id("emailAddressFormInput")).Displayed);
|
Assert.True(s.Driver.FindElement(By.Id("emailAddressFormInput")).Displayed);
|
||||||
SeleniumTester.Driver.FindElement(By.Id("emailAddressFormInput")).SendKeys("@g.com");
|
s.Driver.FindElement(By.Id("emailAddressFormInput")).SendKeys("@g.com");
|
||||||
SeleniumTester.Driver.FindElement(By.Id("emailAddressForm")).FindElement(By.CssSelector("button.action-button"))
|
s.Driver.FindElement(By.Id("emailAddressForm")).FindElement(By.CssSelector("button.action-button"))
|
||||||
.Click();
|
.Click();
|
||||||
|
|
||||||
await Task.Delay(1000);
|
await Task.Delay(1000);
|
||||||
SeleniumTester.Driver.AssertElementNotFound(By.Id("emailAddressFormInput"));
|
s.Driver.AssertElementNotFound(By.Id("emailAddressFormInput"));
|
||||||
|
|
||||||
SeleniumTester.Driver.Navigate().Refresh();
|
s.Driver.Navigate().Refresh();
|
||||||
|
|
||||||
SeleniumTester.Driver.AssertElementNotFound(By.Id("emailAddressFormInput"));
|
s.Driver.AssertElementNotFound(By.Id("emailAddressFormInput"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task CanUseLanguageDropdown()
|
public async Task CanUseLanguageDropdown()
|
||||||
{
|
{
|
||||||
SeleniumTester.RegisterNewUser();
|
using (var s = SeleniumTester.Create())
|
||||||
var store = SeleniumTester.CreateNewStore();
|
{
|
||||||
SeleniumTester.AddDerivationScheme("BTC");
|
s.Start();
|
||||||
|
s.RegisterNewUser();
|
||||||
|
var store = s.CreateNewStore();
|
||||||
|
s.AddDerivationScheme("BTC");
|
||||||
|
|
||||||
var invoiceId = SeleniumTester.CreateInvoice(store.storeName);
|
var invoiceId = s.CreateInvoice(store.storeName);
|
||||||
SeleniumTester.GoToInvoiceCheckout(invoiceId);
|
s.GoToInvoiceCheckout(invoiceId);
|
||||||
Assert.True(SeleniumTester.Driver.FindElement(By.Id("DefaultLang")).FindElements(By.TagName("option")).Count > 1);
|
Assert.True(s.Driver.FindElement(By.Id("DefaultLang")).FindElements(By.TagName("option")).Count > 1);
|
||||||
var payWithTextEnglish = SeleniumTester.Driver.FindElement(By.Id("pay-with-text")).Text;
|
var payWithTextEnglish = s.Driver.FindElement(By.Id("pay-with-text")).Text;
|
||||||
|
|
||||||
var prettyDropdown = SeleniumTester.Driver.FindElement(By.Id("prettydropdown-DefaultLang"));
|
var prettyDropdown = s.Driver.FindElement(By.Id("prettydropdown-DefaultLang"));
|
||||||
prettyDropdown.Click();
|
prettyDropdown.Click();
|
||||||
await Task.Delay(200);
|
await Task.Delay(200);
|
||||||
prettyDropdown.FindElement(By.CssSelector("[data-value=\"da-DK\"]")).Click();
|
prettyDropdown.FindElement(By.CssSelector("[data-value=\"da-DK\"]")).Click();
|
||||||
await Task.Delay(1000);
|
await Task.Delay(1000);
|
||||||
Assert.NotEqual(payWithTextEnglish, SeleniumTester.Driver.FindElement(By.Id("pay-with-text")).Text);
|
Assert.NotEqual(payWithTextEnglish, s.Driver.FindElement(By.Id("pay-with-text")).Text);
|
||||||
SeleniumTester.Driver.Navigate().GoToUrl(SeleniumTester.Driver.Url + "?lang=da-DK");
|
s.Driver.Navigate().GoToUrl(s.Driver.Url + "?lang=da-DK");
|
||||||
|
|
||||||
Assert.NotEqual(payWithTextEnglish, SeleniumTester.Driver.FindElement(By.Id("pay-with-text")).Text);
|
Assert.NotEqual(payWithTextEnglish, s.Driver.FindElement(By.Id("pay-with-text")).Text);
|
||||||
|
|
||||||
|
s.Driver.Quit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void CanUsePaymentMethodDropdown()
|
public void CanUsePaymentMethodDropdown()
|
||||||
{
|
{
|
||||||
SeleniumTester.RegisterNewUser();
|
using (var s = SeleniumTester.Create())
|
||||||
var store = SeleniumTester.CreateNewStore();
|
{
|
||||||
SeleniumTester.AddDerivationScheme("BTC");
|
s.Start();
|
||||||
|
s.RegisterNewUser();
|
||||||
|
var store = s.CreateNewStore();
|
||||||
|
s.AddDerivationScheme("BTC");
|
||||||
|
|
||||||
//check that there is no dropdown since only one payment method is set
|
//check that there is no dropdown since only one payment method is set
|
||||||
var invoiceId = SeleniumTester.CreateInvoice(store.storeName, 10, "USD", "a@g.com");
|
var invoiceId = s.CreateInvoice(store.storeName, 10, "USD", "a@g.com");
|
||||||
SeleniumTester.GoToInvoiceCheckout(invoiceId);
|
s.GoToInvoiceCheckout(invoiceId);
|
||||||
SeleniumTester.Driver.FindElement(By.ClassName("payment__currencies_noborder"));
|
s.Driver.FindElement(By.ClassName("payment__currencies_noborder"));
|
||||||
SeleniumTester.GoToHome();
|
s.GoToHome();
|
||||||
SeleniumTester.GoToStore(store.storeId);
|
s.GoToStore(store.storeId);
|
||||||
SeleniumTester.AddDerivationScheme("LTC");
|
s.AddDerivationScheme("LTC");
|
||||||
SeleniumTester.AddLightningNode("BTC", LightningConnectionType.CLightning);
|
s.AddLightningNode("BTC",LightningConnectionType.CLightning);
|
||||||
//there should be three now
|
//there should be three now
|
||||||
invoiceId = SeleniumTester.CreateInvoice(store.storeName, 10, "USD", "a@g.com");
|
invoiceId = s.CreateInvoice(store.storeName, 10, "USD", "a@g.com");
|
||||||
SeleniumTester.GoToInvoiceCheckout(invoiceId);
|
s.GoToInvoiceCheckout(invoiceId);
|
||||||
var currencyDropdownButton = SeleniumTester.Driver.FindElement(By.ClassName("payment__currencies"));
|
var currencyDropdownButton = s.Driver.FindElement(By.ClassName("payment__currencies"));
|
||||||
Assert.Contains("BTC", currencyDropdownButton.Text);
|
Assert.Contains("BTC", currencyDropdownButton.Text);
|
||||||
currencyDropdownButton.Click();
|
currencyDropdownButton.Click();
|
||||||
|
|
||||||
var elements = SeleniumTester.Driver.FindElement(By.ClassName("vex-content"))
|
var elements = s.Driver.FindElement(By.ClassName("vex-content"))
|
||||||
.FindElements(By.ClassName("vexmenuitem"));
|
.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();
|
||||||
currencyDropdownButton = SeleniumTester.Driver.FindElement(By.ClassName("payment__currencies"));
|
currencyDropdownButton = s.Driver.FindElement(By.ClassName("payment__currencies"));
|
||||||
Assert.Contains("LTC", currencyDropdownButton.Text);
|
Assert.Contains("LTC", currencyDropdownButton.Text);
|
||||||
|
|
||||||
elements = SeleniumTester.Driver.FindElement(By.ClassName("vex-content"))
|
elements = s.Driver.FindElement(By.ClassName("vex-content"))
|
||||||
.FindElements(By.ClassName("vexmenuitem"));
|
.FindElements(By.ClassName("vexmenuitem"));
|
||||||
|
|
||||||
elements.Single(element => element.Text.Contains("Lightning")).Click();
|
elements.Single(element => element.Text.Contains("Lightning")).Click();
|
||||||
|
|
||||||
Assert.Contains("Lightning", currencyDropdownButton.Text);
|
Assert.Contains("Lightning", currencyDropdownButton.Text);
|
||||||
|
|
||||||
|
s.Driver.Quit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void CanUseLightningSatsFeature()
|
public void CanUseLightningSatsFeature()
|
||||||
{
|
{
|
||||||
SeleniumTester.RegisterNewUser();
|
using (var s = SeleniumTester.Create())
|
||||||
var store = SeleniumTester.CreateNewStore();
|
{
|
||||||
SeleniumTester.AddInternalLightningNode("BTC");
|
s.Start();
|
||||||
SeleniumTester.GoToStore(store.storeId, StoreNavPages.Checkout);
|
s.RegisterNewUser();
|
||||||
SeleniumTester.SetCheckbox(SeleniumTester, "LightningAmountInSatoshi", true);
|
var store = s.CreateNewStore();
|
||||||
var command = SeleniumTester.Driver.FindElement(By.Name("command"));
|
s.AddInternalLightningNode("BTC");
|
||||||
|
s.GoToStore(store.storeId, StoreNavPages.Checkout);
|
||||||
|
s.SetCheckbox(s, "LightningAmountInSatoshi", true);
|
||||||
|
var command = s.Driver.FindElement(By.Name("command"));
|
||||||
|
|
||||||
command.ForceClick();
|
command.ForceClick();
|
||||||
var invoiceId = SeleniumTester.CreateInvoice(store.storeName, 10, "USD", "a@g.com");
|
var invoiceId = s.CreateInvoice(store.storeName, 10, "USD", "a@g.com");
|
||||||
SeleniumTester.GoToInvoiceCheckout(invoiceId);
|
s.GoToInvoiceCheckout(invoiceId);
|
||||||
Assert.Contains("Sats", SeleniumTester.Driver.FindElement(By.ClassName("payment__currencies_noborder")).Text);
|
Assert.Contains("Sats", s.Driver.FindElement(By.ClassName("payment__currencies_noborder")).Text);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,42 +27,20 @@ namespace BTCPayServer.Tests
|
|||||||
{
|
{
|
||||||
public class SeleniumTester : IDisposable
|
public class SeleniumTester : IDisposable
|
||||||
{
|
{
|
||||||
private IWebDriver _Driver;
|
public IWebDriver Driver { get; set; }
|
||||||
public IWebDriver Driver
|
public ServerTester Server { get; set; }
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (_Driver == null)
|
|
||||||
{
|
|
||||||
Start();
|
|
||||||
}
|
|
||||||
return _Driver;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private ServerTester _Server;
|
|
||||||
public ServerTester Server
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (_Server == null)
|
|
||||||
{
|
|
||||||
_Server = ServerTester.Create("Default Scope");
|
|
||||||
Start();
|
|
||||||
}
|
|
||||||
return _Server;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SeleniumTester Create([CallerMemberNameAttribute] string scope = null)
|
public static SeleniumTester Create([CallerMemberNameAttribute] string scope = null)
|
||||||
{
|
{
|
||||||
|
var server = ServerTester.Create(scope);
|
||||||
return new SeleniumTester()
|
return new SeleniumTester()
|
||||||
{
|
{
|
||||||
_Server = ServerTester.Create(scope)
|
Server = server
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Start()
|
public void Start()
|
||||||
{
|
{
|
||||||
Server.Start();
|
Server.Start();
|
||||||
ChromeOptions options = new ChromeOptions();
|
ChromeOptions options = new ChromeOptions();
|
||||||
@@ -78,7 +56,7 @@ namespace BTCPayServer.Tests
|
|||||||
{
|
{
|
||||||
options.AddArgument("no-sandbox");
|
options.AddArgument("no-sandbox");
|
||||||
}
|
}
|
||||||
_Driver = new ChromeDriver(Server.PayTester.InContainer ? "/usr/bin" : Directory.GetCurrentDirectory(), options);
|
Driver = new ChromeDriver(Server.PayTester.InContainer ? "/usr/bin" : Directory.GetCurrentDirectory(), options);
|
||||||
if (isDebug)
|
if (isDebug)
|
||||||
{
|
{
|
||||||
//when running locally, depending on your resolution, the website may go into mobile responsive mode and screw with navigation of tests
|
//when running locally, depending on your resolution, the website may go into mobile responsive mode and screw with navigation of tests
|
||||||
@@ -99,10 +77,7 @@ namespace BTCPayServer.Tests
|
|||||||
|
|
||||||
public string RegisterNewUser(bool isAdmin = false)
|
public string RegisterNewUser(bool isAdmin = false)
|
||||||
{
|
{
|
||||||
GoToHome();
|
var usr = RandomUtils.GetUInt256().ToString() + "@a.com";
|
||||||
if (Driver.PageSource.Contains("id=\"Logout\""))
|
|
||||||
Logout();
|
|
||||||
var usr = RandomUtils.GetUInt256().ToString().Substring(20) + "@a.com";
|
|
||||||
Driver.FindElement(By.Id("Register")).Click();
|
Driver.FindElement(By.Id("Register")).Click();
|
||||||
Driver.FindElement(By.Id("Email")).SendKeys(usr);
|
Driver.FindElement(By.Id("Email")).SendKeys(usr);
|
||||||
Driver.FindElement(By.Id("Password")).SendKeys("123456");
|
Driver.FindElement(By.Id("Password")).SendKeys("123456");
|
||||||
|
|||||||
@@ -12,72 +12,79 @@ using System.Threading.Tasks;
|
|||||||
namespace BTCPayServer.Tests
|
namespace BTCPayServer.Tests
|
||||||
{
|
{
|
||||||
[Trait("Selenium", "Selenium")]
|
[Trait("Selenium", "Selenium")]
|
||||||
[Collection("Selenium collection")]
|
|
||||||
public class ChromeTests
|
public class ChromeTests
|
||||||
{
|
{
|
||||||
public SeleniumTester SeleniumTester { get; }
|
public ChromeTests(ITestOutputHelper helper)
|
||||||
|
|
||||||
public ChromeTests(ITestOutputHelper helper, SeleniumTester seleniumTester)
|
|
||||||
{
|
{
|
||||||
Logs.Tester = new XUnitLog(helper) { Name = "Tests" };
|
Logs.Tester = new XUnitLog(helper) { Name = "Tests" };
|
||||||
Logs.LogProvider = new XUnitLogProvider(helper);
|
Logs.LogProvider = new XUnitLogProvider(helper);
|
||||||
SeleniumTester = seleniumTester;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void CanNavigateServerSettings()
|
public void CanNavigateServerSettings()
|
||||||
{
|
{
|
||||||
SeleniumTester.RegisterNewUser(true);
|
using (var s = SeleniumTester.Create())
|
||||||
SeleniumTester.Driver.FindElement(By.Id("ServerSettings")).Click();
|
{
|
||||||
SeleniumTester.Driver.AssertNoError();
|
s.Start();
|
||||||
SeleniumTester.ClickOnAllSideMenus();
|
s.RegisterNewUser(true);
|
||||||
|
s.Driver.FindElement(By.Id("ServerSettings")).Click();
|
||||||
|
s.Driver.AssertNoError();
|
||||||
|
s.ClickOnAllSideMenus();
|
||||||
|
s.Driver.Quit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void NewUserLogin()
|
public void NewUserLogin()
|
||||||
{
|
{
|
||||||
|
using (var s = SeleniumTester.Create())
|
||||||
|
{
|
||||||
|
s.Start();
|
||||||
//Register & Log Out
|
//Register & Log Out
|
||||||
var email = SeleniumTester.RegisterNewUser();
|
var email = s.RegisterNewUser();
|
||||||
SeleniumTester.Driver.FindElement(By.Id("Logout")).Click();
|
s.Driver.FindElement(By.Id("Logout")).Click();
|
||||||
SeleniumTester.Driver.AssertNoError();
|
s.Driver.AssertNoError();
|
||||||
SeleniumTester.Driver.FindElement(By.Id("Login")).Click();
|
s.Driver.FindElement(By.Id("Login")).Click();
|
||||||
SeleniumTester.Driver.AssertNoError();
|
s.Driver.AssertNoError();
|
||||||
|
|
||||||
SeleniumTester.Driver.Navigate().GoToUrl(SeleniumTester.Link("/invoices"));
|
s.Driver.Navigate().GoToUrl(s.Link("/invoices"));
|
||||||
Assert.Contains("ReturnUrl=%2Finvoices", SeleniumTester.Driver.Url);
|
Assert.Contains("ReturnUrl=%2Finvoices", s.Driver.Url);
|
||||||
|
|
||||||
// We should be redirected to login
|
// We should be redirected to login
|
||||||
//Same User Can Log Back In
|
//Same User Can Log Back In
|
||||||
SeleniumTester.Driver.FindElement(By.Id("Email")).SendKeys(email);
|
s.Driver.FindElement(By.Id("Email")).SendKeys(email);
|
||||||
SeleniumTester.Driver.FindElement(By.Id("Password")).SendKeys("123456");
|
s.Driver.FindElement(By.Id("Password")).SendKeys("123456");
|
||||||
SeleniumTester.Driver.FindElement(By.Id("LoginButton")).Click();
|
s.Driver.FindElement(By.Id("LoginButton")).Click();
|
||||||
|
|
||||||
// We should be redirected to invoice
|
// We should be redirected to invoice
|
||||||
Assert.EndsWith("/invoices", SeleniumTester.Driver.Url);
|
Assert.EndsWith("/invoices", s.Driver.Url);
|
||||||
|
|
||||||
// Should not be able to reach server settings
|
// Should not be able to reach server settings
|
||||||
SeleniumTester.Driver.Navigate().GoToUrl(SeleniumTester.Link("/server/users"));
|
s.Driver.Navigate().GoToUrl(s.Link("/server/users"));
|
||||||
Assert.Contains("ReturnUrl=%2Fserver%2Fusers", SeleniumTester.Driver.Url);
|
Assert.Contains("ReturnUrl=%2Fserver%2Fusers", s.Driver.Url);
|
||||||
|
|
||||||
//Change Password & Log Out
|
//Change Password & Log Out
|
||||||
SeleniumTester.Driver.FindElement(By.Id("MySettings")).Click();
|
s.Driver.FindElement(By.Id("MySettings")).Click();
|
||||||
SeleniumTester.Driver.FindElement(By.Id("ChangePassword")).Click();
|
s.Driver.FindElement(By.Id("ChangePassword")).Click();
|
||||||
SeleniumTester.Driver.FindElement(By.Id("OldPassword")).SendKeys("123456");
|
s.Driver.FindElement(By.Id("OldPassword")).SendKeys("123456");
|
||||||
SeleniumTester.Driver.FindElement(By.Id("NewPassword")).SendKeys("abc???");
|
s.Driver.FindElement(By.Id("NewPassword")).SendKeys("abc???");
|
||||||
SeleniumTester.Driver.FindElement(By.Id("ConfirmPassword")).SendKeys("abc???");
|
s.Driver.FindElement(By.Id("ConfirmPassword")).SendKeys("abc???");
|
||||||
SeleniumTester.Driver.FindElement(By.Id("UpdatePassword")).Click();
|
s.Driver.FindElement(By.Id("UpdatePassword")).Click();
|
||||||
SeleniumTester.Driver.FindElement(By.Id("Logout")).Click();
|
s.Driver.FindElement(By.Id("Logout")).Click();
|
||||||
SeleniumTester.Driver.AssertNoError();
|
s.Driver.AssertNoError();
|
||||||
|
|
||||||
//Log In With New Password
|
//Log In With New Password
|
||||||
SeleniumTester.Driver.FindElement(By.Id("Login")).Click();
|
s.Driver.FindElement(By.Id("Login")).Click();
|
||||||
SeleniumTester.Driver.FindElement(By.Id("Email")).SendKeys(email);
|
s.Driver.FindElement(By.Id("Email")).SendKeys(email);
|
||||||
SeleniumTester.Driver.FindElement(By.Id("Password")).SendKeys("abc???");
|
s.Driver.FindElement(By.Id("Password")).SendKeys("abc???");
|
||||||
SeleniumTester.Driver.FindElement(By.Id("LoginButton")).Click();
|
s.Driver.FindElement(By.Id("LoginButton")).Click();
|
||||||
Assert.True(SeleniumTester.Driver.PageSource.Contains("Stores"), "Can't Access Stores");
|
Assert.True(s.Driver.PageSource.Contains("Stores"), "Can't Access Stores");
|
||||||
|
|
||||||
SeleniumTester.Driver.FindElement(By.Id("MySettings")).Click();
|
s.Driver.FindElement(By.Id("MySettings")).Click();
|
||||||
SeleniumTester.ClickOnAllSideMenus();
|
s.ClickOnAllSideMenus();
|
||||||
|
|
||||||
|
s.Driver.Quit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void LogIn(SeleniumTester s, string email)
|
static void LogIn(SeleniumTester s, string email)
|
||||||
@@ -91,110 +98,122 @@ namespace BTCPayServer.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public async Task CanUseSSHService()
|
public async Task CanUseSSHService()
|
||||||
{
|
{
|
||||||
var alice = SeleniumTester.RegisterNewUser(isAdmin: true);
|
using (var s = SeleniumTester.Create())
|
||||||
SeleniumTester.Driver.Navigate().GoToUrl(SeleniumTester.Link("/server/services"));
|
{
|
||||||
Assert.Contains("server/services/ssh", SeleniumTester.Driver.PageSource);
|
s.Start();
|
||||||
using (var client = await SeleniumTester.Server.PayTester.GetService<BTCPayServer.Configuration.BTCPayServerOptions>().SSHSettings.ConnectAsync())
|
var alice = s.RegisterNewUser(isAdmin: true);
|
||||||
|
s.Driver.Navigate().GoToUrl(s.Link("/server/services"));
|
||||||
|
Assert.Contains("server/services/ssh", s.Driver.PageSource);
|
||||||
|
using (var client = await s.Server.PayTester.GetService<BTCPayServer.Configuration.BTCPayServerOptions>().SSHSettings.ConnectAsync())
|
||||||
{
|
{
|
||||||
var result = await client.RunBash("echo hello");
|
var result = await client.RunBash("echo hello");
|
||||||
Assert.Equal(string.Empty, result.Error);
|
Assert.Equal(string.Empty, result.Error);
|
||||||
Assert.Equal("hello\n", result.Output);
|
Assert.Equal("hello\n", result.Output);
|
||||||
Assert.Equal(0, result.ExitStatus);
|
Assert.Equal(0, result.ExitStatus);
|
||||||
}
|
}
|
||||||
SeleniumTester.Driver.Navigate().GoToUrl(SeleniumTester.Link("/server/services/ssh"));
|
s.Driver.Navigate().GoToUrl(s.Link("/server/services/ssh"));
|
||||||
SeleniumTester.Driver.AssertNoError();
|
s.Driver.AssertNoError();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void CanUseDynamicDns()
|
public void CanUseDynamicDns()
|
||||||
{
|
{
|
||||||
var alice = SeleniumTester.RegisterNewUser(isAdmin: true);
|
using (var s = SeleniumTester.Create())
|
||||||
SeleniumTester.Driver.Navigate().GoToUrl(SeleniumTester.Link("/server/services"));
|
{
|
||||||
Assert.Contains("Dynamic DNS", SeleniumTester.Driver.PageSource);
|
s.Start();
|
||||||
|
var alice = s.RegisterNewUser(isAdmin: true);
|
||||||
|
s.Driver.Navigate().GoToUrl(s.Link("/server/services"));
|
||||||
|
Assert.Contains("Dynamic DNS", s.Driver.PageSource);
|
||||||
|
|
||||||
SeleniumTester.Driver.Navigate().GoToUrl(SeleniumTester.Link("/server/services/dynamic-dns"));
|
s.Driver.Navigate().GoToUrl(s.Link("/server/services/dynamic-dns"));
|
||||||
SeleniumTester.Driver.AssertNoError();
|
s.Driver.AssertNoError();
|
||||||
if (SeleniumTester.Driver.PageSource.Contains("pouet.hello.com"))
|
if (s.Driver.PageSource.Contains("pouet.hello.com"))
|
||||||
{
|
{
|
||||||
// Cleanup old test run
|
// Cleanup old test run
|
||||||
SeleniumTester.Driver.Navigate().GoToUrl(SeleniumTester.Link("/server/services/dynamic-dns/pouet.hello.com/delete"));
|
s.Driver.Navigate().GoToUrl(s.Link("/server/services/dynamic-dns/pouet.hello.com/delete"));
|
||||||
SeleniumTester.Driver.FindElement(By.Id("continue")).Click();
|
s.Driver.FindElement(By.Id("continue")).Click();
|
||||||
}
|
}
|
||||||
SeleniumTester.Driver.FindElement(By.Id("AddDynamicDNS")).Click();
|
s.Driver.FindElement(By.Id("AddDynamicDNS")).Click();
|
||||||
SeleniumTester.Driver.AssertNoError();
|
s.Driver.AssertNoError();
|
||||||
// We will just cheat for test purposes by only querying the server
|
// We will just cheat for test purposes by only querying the server
|
||||||
SeleniumTester.Driver.FindElement(By.Id("ServiceUrl")).SendKeys(SeleniumTester.Link("/"));
|
s.Driver.FindElement(By.Id("ServiceUrl")).SendKeys(s.Link("/"));
|
||||||
SeleniumTester.Driver.FindElement(By.Id("Settings_Hostname")).SendKeys("pouet.hello.com");
|
s.Driver.FindElement(By.Id("Settings_Hostname")).SendKeys("pouet.hello.com");
|
||||||
SeleniumTester.Driver.FindElement(By.Id("Settings_Login")).SendKeys("MyLog");
|
s.Driver.FindElement(By.Id("Settings_Login")).SendKeys("MyLog");
|
||||||
SeleniumTester.Driver.FindElement(By.Id("Settings_Password")).SendKeys("MyLog" + Keys.Enter);
|
s.Driver.FindElement(By.Id("Settings_Password")).SendKeys("MyLog" + Keys.Enter);
|
||||||
SeleniumTester.Driver.AssertNoError();
|
s.Driver.AssertNoError();
|
||||||
Assert.Contains("The Dynamic DNS has been successfully queried", SeleniumTester.Driver.PageSource);
|
Assert.Contains("The Dynamic DNS has been successfully queried", s.Driver.PageSource);
|
||||||
Assert.EndsWith("/server/services/dynamic-dns", SeleniumTester.Driver.Url);
|
Assert.EndsWith("/server/services/dynamic-dns", s.Driver.Url);
|
||||||
|
|
||||||
// Try to do the same thing should fail (hostname already exists)
|
// Try to do the same thing should fail (hostname already exists)
|
||||||
SeleniumTester.Driver.FindElement(By.Id("AddDynamicDNS")).Click();
|
s.Driver.FindElement(By.Id("AddDynamicDNS")).Click();
|
||||||
SeleniumTester.Driver.AssertNoError();
|
s.Driver.AssertNoError();
|
||||||
SeleniumTester.Driver.FindElement(By.Id("ServiceUrl")).SendKeys(SeleniumTester.Link("/"));
|
s.Driver.FindElement(By.Id("ServiceUrl")).SendKeys(s.Link("/"));
|
||||||
SeleniumTester.Driver.FindElement(By.Id("Settings_Hostname")).SendKeys("pouet.hello.com");
|
s.Driver.FindElement(By.Id("Settings_Hostname")).SendKeys("pouet.hello.com");
|
||||||
SeleniumTester.Driver.FindElement(By.Id("Settings_Login")).SendKeys("MyLog");
|
s.Driver.FindElement(By.Id("Settings_Login")).SendKeys("MyLog");
|
||||||
SeleniumTester.Driver.FindElement(By.Id("Settings_Password")).SendKeys("MyLog" + Keys.Enter);
|
s.Driver.FindElement(By.Id("Settings_Password")).SendKeys("MyLog" + Keys.Enter);
|
||||||
SeleniumTester.Driver.AssertNoError();
|
s.Driver.AssertNoError();
|
||||||
Assert.Contains("This hostname already exists", SeleniumTester.Driver.PageSource);
|
Assert.Contains("This hostname already exists", s.Driver.PageSource);
|
||||||
|
|
||||||
// Delete it
|
// Delete it
|
||||||
SeleniumTester.Driver.Navigate().GoToUrl(SeleniumTester.Link("/server/services/dynamic-dns"));
|
s.Driver.Navigate().GoToUrl(s.Link("/server/services/dynamic-dns"));
|
||||||
Assert.Contains("/server/services/dynamic-dns/pouet.hello.com/delete", SeleniumTester.Driver.PageSource);
|
Assert.Contains("/server/services/dynamic-dns/pouet.hello.com/delete", s.Driver.PageSource);
|
||||||
SeleniumTester.Driver.Navigate().GoToUrl(SeleniumTester.Link("/server/services/dynamic-dns/pouet.hello.com/delete"));
|
s.Driver.Navigate().GoToUrl(s.Link("/server/services/dynamic-dns/pouet.hello.com/delete"));
|
||||||
SeleniumTester.Driver.FindElement(By.Id("continue")).Click();
|
s.Driver.FindElement(By.Id("continue")).Click();
|
||||||
SeleniumTester.Driver.AssertNoError();
|
s.Driver.AssertNoError();
|
||||||
|
|
||||||
Assert.DoesNotContain("/server/services/dynamic-dns/pouet.hello.com/delete", SeleniumTester.Driver.PageSource);
|
Assert.DoesNotContain("/server/services/dynamic-dns/pouet.hello.com/delete", s.Driver.PageSource);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void CanCreateStores()
|
public void CanCreateStores()
|
||||||
{
|
{
|
||||||
var alice = SeleniumTester.RegisterNewUser();
|
using (var s = SeleniumTester.Create())
|
||||||
var store = SeleniumTester.CreateNewStore().storeName;
|
{
|
||||||
SeleniumTester.AddDerivationScheme();
|
s.Start();
|
||||||
SeleniumTester.Driver.AssertNoError();
|
var alice = s.RegisterNewUser();
|
||||||
Assert.Contains(store, SeleniumTester.Driver.PageSource);
|
var store = s.CreateNewStore().storeName;
|
||||||
var storeUrl = SeleniumTester.Driver.Url;
|
s.AddDerivationScheme();
|
||||||
SeleniumTester.ClickOnAllSideMenus();
|
s.Driver.AssertNoError();
|
||||||
SeleniumTester.GoToInvoices();
|
Assert.Contains(store, s.Driver.PageSource);
|
||||||
SeleniumTester.CreateInvoice(store);
|
var storeUrl = s.Driver.Url;
|
||||||
SeleniumTester.Driver.FindElement(By.ClassName("invoice-details-link")).Click();
|
s.ClickOnAllSideMenus();
|
||||||
var invoiceUrl = SeleniumTester.Driver.Url;
|
s.GoToInvoices();
|
||||||
|
s.CreateInvoice(store);
|
||||||
|
s.Driver.FindElement(By.ClassName("invoice-details-link")).Click();
|
||||||
|
var invoiceUrl = s.Driver.Url;
|
||||||
|
|
||||||
// When logout we should not be able to access store and invoice details
|
// When logout we should not be able to access store and invoice details
|
||||||
SeleniumTester.Driver.FindElement(By.Id("Logout")).Click();
|
s.Driver.FindElement(By.Id("Logout")).Click();
|
||||||
SeleniumTester.Driver.Navigate().GoToUrl(storeUrl);
|
s.Driver.Navigate().GoToUrl(storeUrl);
|
||||||
Assert.Contains("ReturnUrl", SeleniumTester.Driver.Url);
|
Assert.Contains("ReturnUrl", s.Driver.Url);
|
||||||
SeleniumTester.Driver.Navigate().GoToUrl(invoiceUrl);
|
s.Driver.Navigate().GoToUrl(invoiceUrl);
|
||||||
Assert.Contains("ReturnUrl", SeleniumTester.Driver.Url);
|
Assert.Contains("ReturnUrl", s.Driver.Url);
|
||||||
|
|
||||||
// When logged we should not be able to access store and invoice details
|
// When logged we should not be able to access store and invoice details
|
||||||
var bob = SeleniumTester.RegisterNewUser();
|
var bob = s.RegisterNewUser();
|
||||||
SeleniumTester.Driver.Navigate().GoToUrl(storeUrl);
|
s.Driver.Navigate().GoToUrl(storeUrl);
|
||||||
Assert.Contains("ReturnUrl", SeleniumTester.Driver.Url);
|
Assert.Contains("ReturnUrl", s.Driver.Url);
|
||||||
SeleniumTester.Driver.Navigate().GoToUrl(invoiceUrl);
|
s.Driver.Navigate().GoToUrl(invoiceUrl);
|
||||||
SeleniumTester.AssertNotFound();
|
s.AssertNotFound();
|
||||||
SeleniumTester.GoToHome();
|
s.GoToHome();
|
||||||
SeleniumTester.Logout();
|
s.Logout();
|
||||||
|
|
||||||
// Let's add Bob as a guest to alice's store
|
// Let's add Bob as a guest to alice's store
|
||||||
LogIn(SeleniumTester, alice);
|
LogIn(s, alice);
|
||||||
SeleniumTester.Driver.Navigate().GoToUrl(storeUrl + "/users");
|
s.Driver.Navigate().GoToUrl(storeUrl + "/users");
|
||||||
SeleniumTester.Driver.FindElement(By.Id("Email")).SendKeys(bob + Keys.Enter);
|
s.Driver.FindElement(By.Id("Email")).SendKeys(bob + Keys.Enter);
|
||||||
Assert.Contains("User added successfully", SeleniumTester.Driver.PageSource);
|
Assert.Contains("User added successfully", s.Driver.PageSource);
|
||||||
SeleniumTester.Logout();
|
s.Logout();
|
||||||
|
|
||||||
// Bob should not have access to store, but should have access to invoice
|
// Bob should not have access to store, but should have access to invoice
|
||||||
LogIn(SeleniumTester, bob);
|
LogIn(s, bob);
|
||||||
SeleniumTester.Driver.Navigate().GoToUrl(storeUrl);
|
s.Driver.Navigate().GoToUrl(storeUrl);
|
||||||
Assert.Contains("ReturnUrl", SeleniumTester.Driver.Url);
|
Assert.Contains("ReturnUrl", s.Driver.Url);
|
||||||
SeleniumTester.Driver.Navigate().GoToUrl(invoiceUrl);
|
s.Driver.Navigate().GoToUrl(invoiceUrl);
|
||||||
SeleniumTester.Driver.AssertNoError();
|
s.Driver.AssertNoError();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -202,120 +221,138 @@ namespace BTCPayServer.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void CanCreateAppPoS()
|
public void CanCreateAppPoS()
|
||||||
{
|
{
|
||||||
SeleniumTester.RegisterNewUser();
|
using (var s = SeleniumTester.Create())
|
||||||
var store = SeleniumTester.CreateNewStore();
|
{
|
||||||
|
s.Start();
|
||||||
|
s.RegisterNewUser();
|
||||||
|
var store = s.CreateNewStore();
|
||||||
|
|
||||||
SeleniumTester.Driver.FindElement(By.Id("Apps")).Click();
|
s.Driver.FindElement(By.Id("Apps")).Click();
|
||||||
SeleniumTester.Driver.FindElement(By.Id("CreateNewApp")).Click();
|
s.Driver.FindElement(By.Id("CreateNewApp")).Click();
|
||||||
SeleniumTester.Driver.FindElement(By.Name("Name")).SendKeys("PoS" + Guid.NewGuid());
|
s.Driver.FindElement(By.Name("Name")).SendKeys("PoS" + Guid.NewGuid());
|
||||||
SeleniumTester.Driver.FindElement(By.Id("SelectedAppType")).SendKeys("PointOfSale" + Keys.Enter);
|
s.Driver.FindElement(By.Id("SelectedAppType")).SendKeys("PointOfSale" + Keys.Enter);
|
||||||
SeleniumTester.Driver.FindElement(By.Id("SelectedStore")).SendKeys(store + Keys.Enter);
|
s.Driver.FindElement(By.Id("SelectedStore")).SendKeys(store + Keys.Enter);
|
||||||
SeleniumTester.Driver.FindElement(By.Id("Create")).Click();
|
s.Driver.FindElement(By.Id("Create")).Click();
|
||||||
SeleniumTester.Driver.FindElement(By.Id("EnableShoppingCart")).Click();
|
s.Driver.FindElement(By.Id("EnableShoppingCart")).Click();
|
||||||
SeleniumTester.Driver.FindElement(By.Id("SaveSettings")).ForceClick();
|
s.Driver.FindElement(By.Id("SaveSettings")).ForceClick();
|
||||||
SeleniumTester.Driver.FindElement(By.Id("ViewApp")).ForceClick();
|
s.Driver.FindElement(By.Id("ViewApp")).ForceClick();
|
||||||
SeleniumTester.Driver.SwitchTo().Window(SeleniumTester.Driver.WindowHandles.Last());
|
s.Driver.SwitchTo().Window(s.Driver.WindowHandles.Last());
|
||||||
Assert.True(SeleniumTester.Driver.PageSource.Contains("Tea shop"), "Unable to create PoS");
|
Assert.True(s.Driver.PageSource.Contains("Tea shop"), "Unable to create PoS");
|
||||||
|
s.Driver.Quit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void CanCreateAppCF()
|
public void CanCreateAppCF()
|
||||||
{
|
{
|
||||||
SeleniumTester.RegisterNewUser();
|
using (var s = SeleniumTester.Create())
|
||||||
var store = SeleniumTester.CreateNewStore();
|
{
|
||||||
SeleniumTester.AddDerivationScheme();
|
s.Start();
|
||||||
|
s.RegisterNewUser();
|
||||||
|
var store = s.CreateNewStore();
|
||||||
|
s.AddDerivationScheme();
|
||||||
|
|
||||||
SeleniumTester.Driver.FindElement(By.Id("Apps")).Click();
|
s.Driver.FindElement(By.Id("Apps")).Click();
|
||||||
SeleniumTester.Driver.FindElement(By.Id("CreateNewApp")).Click();
|
s.Driver.FindElement(By.Id("CreateNewApp")).Click();
|
||||||
SeleniumTester.Driver.FindElement(By.Name("Name")).SendKeys("CF" + Guid.NewGuid());
|
s.Driver.FindElement(By.Name("Name")).SendKeys("CF" + Guid.NewGuid());
|
||||||
SeleniumTester.Driver.FindElement(By.Id("SelectedAppType")).SendKeys("Crowdfund" + Keys.Enter);
|
s.Driver.FindElement(By.Id("SelectedAppType")).SendKeys("Crowdfund" + Keys.Enter);
|
||||||
SeleniumTester.Driver.FindElement(By.Id("SelectedStore")).SendKeys(store + Keys.Enter);
|
s.Driver.FindElement(By.Id("SelectedStore")).SendKeys(store + Keys.Enter);
|
||||||
SeleniumTester.Driver.FindElement(By.Id("Create")).Click();
|
s.Driver.FindElement(By.Id("Create")).Click();
|
||||||
SeleniumTester.Driver.FindElement(By.Id("Title")).SendKeys("Kukkstarter");
|
s.Driver.FindElement(By.Id("Title")).SendKeys("Kukkstarter");
|
||||||
SeleniumTester.Driver.FindElement(By.CssSelector("div.note-editable.card-block")).SendKeys("1BTC = 1BTC");
|
s.Driver.FindElement(By.CssSelector("div.note-editable.card-block")).SendKeys("1BTC = 1BTC");
|
||||||
SeleniumTester.Driver.FindElement(By.Id("TargetCurrency")).SendKeys("JPY");
|
s.Driver.FindElement(By.Id("TargetCurrency")).SendKeys("JPY");
|
||||||
SeleniumTester.Driver.FindElement(By.Id("TargetAmount")).SendKeys("700");
|
s.Driver.FindElement(By.Id("TargetAmount")).SendKeys("700");
|
||||||
SeleniumTester.Driver.FindElement(By.Id("SaveSettings")).ForceClick();
|
s.Driver.FindElement(By.Id("SaveSettings")).ForceClick();
|
||||||
SeleniumTester.Driver.FindElement(By.Id("ViewApp")).ForceClick();
|
s.Driver.FindElement(By.Id("ViewApp")).ForceClick();
|
||||||
SeleniumTester.Driver.SwitchTo().Window(SeleniumTester.Driver.WindowHandles.Last());
|
s.Driver.SwitchTo().Window(s.Driver.WindowHandles.Last());
|
||||||
Assert.True(SeleniumTester.Driver.PageSource.Contains("Currently Active!"), "Unable to create CF");
|
Assert.True(s.Driver.PageSource.Contains("Currently Active!"), "Unable to create CF");
|
||||||
|
s.Driver.Quit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void CanCreatePayRequest()
|
public void CanCreatePayRequest()
|
||||||
{
|
{
|
||||||
SeleniumTester.RegisterNewUser();
|
using (var s = SeleniumTester.Create())
|
||||||
SeleniumTester.CreateNewStore();
|
{
|
||||||
SeleniumTester.AddDerivationScheme();
|
s.Start();
|
||||||
|
s.RegisterNewUser();
|
||||||
|
s.CreateNewStore();
|
||||||
|
s.AddDerivationScheme();
|
||||||
|
|
||||||
SeleniumTester.Driver.FindElement(By.Id("PaymentRequests")).Click();
|
s.Driver.FindElement(By.Id("PaymentRequests")).Click();
|
||||||
SeleniumTester.Driver.FindElement(By.Id("CreatePaymentRequest")).Click();
|
s.Driver.FindElement(By.Id("CreatePaymentRequest")).Click();
|
||||||
SeleniumTester.Driver.FindElement(By.Id("Title")).SendKeys("Pay123");
|
s.Driver.FindElement(By.Id("Title")).SendKeys("Pay123");
|
||||||
SeleniumTester.Driver.FindElement(By.Id("Amount")).SendKeys("700");
|
s.Driver.FindElement(By.Id("Amount")).SendKeys("700");
|
||||||
SeleniumTester.Driver.FindElement(By.Id("Currency")).SendKeys("BTC");
|
s.Driver.FindElement(By.Id("Currency")).SendKeys("BTC");
|
||||||
SeleniumTester.Driver.FindElement(By.Id("SaveButton")).ForceClick();
|
s.Driver.FindElement(By.Id("SaveButton")).ForceClick();
|
||||||
SeleniumTester.Driver.FindElement(By.Name("ViewAppButton")).SendKeys(Keys.Return);
|
s.Driver.FindElement(By.Name("ViewAppButton")).SendKeys(Keys.Return);
|
||||||
SeleniumTester.Driver.SwitchTo().Window(SeleniumTester.Driver.WindowHandles.Last());
|
s.Driver.SwitchTo().Window(s.Driver.WindowHandles.Last());
|
||||||
Assert.True(SeleniumTester.Driver.PageSource.Contains("Amount due"), "Unable to create Payment Request");
|
Assert.True(s.Driver.PageSource.Contains("Amount due"), "Unable to create Payment Request");
|
||||||
|
s.Driver.Quit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void CanManageWallet()
|
public void CanManageWallet()
|
||||||
{
|
{
|
||||||
SeleniumTester.RegisterNewUser();
|
using (var s = SeleniumTester.Create())
|
||||||
SeleniumTester.CreateNewStore();
|
{
|
||||||
|
s.Start();
|
||||||
|
s.RegisterNewUser();
|
||||||
|
s.CreateNewStore();
|
||||||
|
|
||||||
// In this test, we try to spend from a manual seed. We import the xpub 49'/0'/0', then try to use the seed
|
// In this test, we try to spend from a manual seed. We import the xpub 49'/0'/0', then try to use the seed
|
||||||
// to sign the transaction
|
// to sign the transaction
|
||||||
var mnemonic = "usage fever hen zero slide mammal silent heavy donate budget pulse say brain thank sausage brand craft about save attract muffin advance illegal cabbage";
|
var mnemonic = "usage fever hen zero slide mammal silent heavy donate budget pulse say brain thank sausage brand craft about save attract muffin advance illegal cabbage";
|
||||||
var root = new Mnemonic(mnemonic).DeriveExtKey();
|
var root = new Mnemonic(mnemonic).DeriveExtKey();
|
||||||
SeleniumTester.AddDerivationScheme("BTC", "ypub6WWc2gWwHbdnAAyJDnR4SPL1phRh7REqrPBfZeizaQ1EmTshieRXJC3Z5YoU4wkcdKHEjQGkh6AYEzCQC1Kz3DNaWSwdc1pc8416hAjzqyD");
|
s.AddDerivationScheme("BTC", "ypub6WWc2gWwHbdnAAyJDnR4SPL1phRh7REqrPBfZeizaQ1EmTshieRXJC3Z5YoU4wkcdKHEjQGkh6AYEzCQC1Kz3DNaWSwdc1pc8416hAjzqyD");
|
||||||
var tx = SeleniumTester.Server.ExplorerNode.SendToAddress(BitcoinAddress.Create("bcrt1qmxg8fgnmkp354vhe78j6sr4ut64tyz2xyejel4", Network.RegTest), Money.Coins(3.0m));
|
var tx = s.Server.ExplorerNode.SendToAddress(BitcoinAddress.Create("bcrt1qmxg8fgnmkp354vhe78j6sr4ut64tyz2xyejel4", Network.RegTest), Money.Coins(3.0m));
|
||||||
SeleniumTester.Server.ExplorerNode.Generate(1);
|
s.Server.ExplorerNode.Generate(1);
|
||||||
|
|
||||||
SeleniumTester.Driver.FindElement(By.Id("Wallets")).Click();
|
s.Driver.FindElement(By.Id("Wallets")).Click();
|
||||||
SeleniumTester.Driver.FindElement(By.LinkText("Manage")).Click();
|
s.Driver.FindElement(By.LinkText("Manage")).Click();
|
||||||
|
|
||||||
SeleniumTester.ClickOnAllSideMenus();
|
s.ClickOnAllSideMenus();
|
||||||
|
|
||||||
// We setup the fingerprint and the account key path
|
// We setup the fingerprint and the account key path
|
||||||
SeleniumTester.Driver.FindElement(By.Id("WalletSettings")).ForceClick();
|
s.Driver.FindElement(By.Id("WalletSettings")).ForceClick();
|
||||||
SeleniumTester.Driver.FindElement(By.Id("AccountKeys_0__MasterFingerprint")).SendKeys("8bafd160");
|
s.Driver.FindElement(By.Id("AccountKeys_0__MasterFingerprint")).SendKeys("8bafd160");
|
||||||
SeleniumTester.Driver.FindElement(By.Id("AccountKeys_0__AccountKeyPath")).SendKeys("m/49'/0'/0'" + Keys.Enter);
|
s.Driver.FindElement(By.Id("AccountKeys_0__AccountKeyPath")).SendKeys("m/49'/0'/0'" + Keys.Enter);
|
||||||
|
|
||||||
// Check the tx sent earlier arrived
|
// Check the tx sent earlier arrived
|
||||||
SeleniumTester.Driver.FindElement(By.Id("WalletTransactions")).ForceClick();
|
s.Driver.FindElement(By.Id("WalletTransactions")).ForceClick();
|
||||||
var walletTransactionLink = SeleniumTester.Driver.Url;
|
var walletTransactionLink = s.Driver.Url;
|
||||||
Assert.Contains(tx.ToString(), SeleniumTester.Driver.PageSource);
|
Assert.Contains(tx.ToString(), s.Driver.PageSource);
|
||||||
|
|
||||||
|
|
||||||
void SignWith(string signingSource)
|
void SignWith(string signingSource)
|
||||||
{
|
{
|
||||||
// Send to bob
|
// Send to bob
|
||||||
SeleniumTester.Driver.FindElement(By.Id("WalletSend")).Click();
|
s.Driver.FindElement(By.Id("WalletSend")).Click();
|
||||||
var bob = new Key().PubKey.Hash.GetAddress(Network.RegTest);
|
var bob = new Key().PubKey.Hash.GetAddress(Network.RegTest);
|
||||||
SetTransactionOutput(0, bob, 1);
|
SetTransactionOutput(0, bob, 1);
|
||||||
SeleniumTester.Driver.ScrollTo(By.Id("SendMenu"));
|
s.Driver.ScrollTo(By.Id("SendMenu"));
|
||||||
SeleniumTester.Driver.FindElement(By.Id("SendMenu")).ForceClick();
|
s.Driver.FindElement(By.Id("SendMenu")).ForceClick();
|
||||||
SeleniumTester.Driver.FindElement(By.CssSelector("button[value=seed]")).Click();
|
s.Driver.FindElement(By.CssSelector("button[value=seed]")).Click();
|
||||||
|
|
||||||
// Input the seed
|
// Input the seed
|
||||||
SeleniumTester.Driver.FindElement(By.Id("SeedOrKey")).SendKeys(signingSource + Keys.Enter);
|
s.Driver.FindElement(By.Id("SeedOrKey")).SendKeys(signingSource + Keys.Enter);
|
||||||
|
|
||||||
// Broadcast
|
// Broadcast
|
||||||
Assert.Contains(bob.ToString(), SeleniumTester.Driver.PageSource);
|
Assert.Contains(bob.ToString(), s.Driver.PageSource);
|
||||||
Assert.Contains("1.00000000", SeleniumTester.Driver.PageSource);
|
Assert.Contains("1.00000000", s.Driver.PageSource);
|
||||||
SeleniumTester.Driver.FindElement(By.CssSelector("button[value=broadcast]")).ForceClick();
|
s.Driver.FindElement(By.CssSelector("button[value=broadcast]")).ForceClick();
|
||||||
Assert.Equal(walletTransactionLink, SeleniumTester.Driver.Url);
|
Assert.Equal(walletTransactionLink, s.Driver.Url);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetTransactionOutput(int index, BitcoinAddress dest, decimal amount, bool subtract = false)
|
void SetTransactionOutput(int index, BitcoinAddress dest, decimal amount, bool subtract = false)
|
||||||
{
|
{
|
||||||
SeleniumTester.Driver.FindElement(By.Id($"Outputs_{index}__DestinationAddress")).SendKeys(dest.ToString());
|
s.Driver.FindElement(By.Id($"Outputs_{index}__DestinationAddress")).SendKeys(dest.ToString());
|
||||||
var amountElement = SeleniumTester.Driver.FindElement(By.Id($"Outputs_{index}__Amount"));
|
var amountElement = s.Driver.FindElement(By.Id($"Outputs_{index}__Amount"));
|
||||||
amountElement.Clear();
|
amountElement.Clear();
|
||||||
amountElement.SendKeys(amount.ToString());
|
amountElement.SendKeys(amount.ToString());
|
||||||
var checkboxElement = SeleniumTester.Driver.FindElement(By.Id($"Outputs_{index}__SubtractFeesFromOutput"));
|
var checkboxElement = s.Driver.FindElement(By.Id($"Outputs_{index}__SubtractFeesFromOutput"));
|
||||||
if (checkboxElement.Selected != subtract)
|
if (checkboxElement.Selected != subtract)
|
||||||
{
|
{
|
||||||
checkboxElement.Click();
|
checkboxElement.Click();
|
||||||
@@ -327,3 +364,4 @@ namespace BTCPayServer.Tests
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Text;
|
|
||||||
using Xunit;
|
|
||||||
using Xunit.Sdk;
|
|
||||||
|
|
||||||
namespace BTCPayServer.Tests
|
|
||||||
{
|
|
||||||
[CollectionDefinition("Selenium collection")]
|
|
||||||
public class SeleniumCollection : ICollectionFixture<SeleniumTester>
|
|
||||||
{
|
|
||||||
// This class has no code, and is never created. Its purpose is simply
|
|
||||||
// to be the place to apply [CollectionDefinition] and all the
|
|
||||||
// ICollectionFixture<> interfaces.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -13,7 +13,6 @@ using BTCPayServer.Services.Invoices;
|
|||||||
using BTCPayServer.Services;
|
using BTCPayServer.Services;
|
||||||
using BTCPayServer.Services.Rates;
|
using BTCPayServer.Services.Rates;
|
||||||
using NBitcoin;
|
using NBitcoin;
|
||||||
using System.Globalization;
|
|
||||||
|
|
||||||
namespace BTCPayServer.Payments.Lightning
|
namespace BTCPayServer.Payments.Lightning
|
||||||
{
|
{
|
||||||
@@ -178,10 +177,10 @@ namespace BTCPayServer.Payments.Lightning
|
|||||||
if (storeBlob.LightningAmountInSatoshi && model.CryptoCode == "BTC" )
|
if (storeBlob.LightningAmountInSatoshi && model.CryptoCode == "BTC" )
|
||||||
{
|
{
|
||||||
model.CryptoCode = "Sats";
|
model.CryptoCode = "Sats";
|
||||||
model.BtcDue = Money.Parse(model.BtcDue).ToUnit(MoneyUnit.Satoshi).ToString(CultureInfo.InvariantCulture);
|
model.BtcDue = Money.Parse(model.BtcDue).ToUnit(MoneyUnit.Satoshi).ToString();
|
||||||
model.BtcPaid = Money.Parse(model.BtcPaid).ToUnit(MoneyUnit.Satoshi).ToString(CultureInfo.InvariantCulture);
|
model.BtcPaid = Money.Parse(model.BtcPaid).ToUnit(MoneyUnit.Satoshi).ToString();
|
||||||
model.NetworkFee = new Money(model.NetworkFee, MoneyUnit.BTC).ToUnit(MoneyUnit.Satoshi);
|
model.NetworkFee = new Money(model.NetworkFee, MoneyUnit.BTC).ToUnit(MoneyUnit.Satoshi);
|
||||||
model.OrderAmount = Money.Parse(model.OrderAmount).ToUnit(MoneyUnit.Satoshi).ToString(CultureInfo.InvariantCulture);
|
model.OrderAmount = Money.Parse(model.OrderAmount).ToUnit(MoneyUnit.Satoshi).ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public override string GetCryptoImage(PaymentMethodId paymentMethodId)
|
public override string GetCryptoImage(PaymentMethodId paymentMethodId)
|
||||||
|
|||||||
Reference in New Issue
Block a user