Skip to content

Commit

Permalink
Fix for ui tests. Added extrsa timeout + added switch to new iframe (#51
Browse files Browse the repository at this point in the history
)

Co-authored-by: Clement Joye <clement.joye@authority.se>
  • Loading branch information
lounge and clement-joye authored Jul 6, 2022
1 parent 38d3c23 commit f5a9bf9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Atata;
using OpenQA.Selenium;
using Sample.AspNetCore.SystemTests.PageObjectModels;
using Sample.AspNetCore.SystemTests.PageObjectModels.Payment;
using Sample.AspNetCore.SystemTests.Services;
Expand All @@ -8,24 +9,49 @@ namespace Sample.AspNetCore.SystemTests.Test.Helpers
{
public static class PaymentHelper
{
public static SveaPaymentFramePage PayWithCard(this SveaPaymentFramePage page)
public static SveaPaymentFramePage PayWithCard(this SveaPaymentFramePage page, bool switchFrame = false)
{
return page
.PaymentMethods.Card.IsVisible.WaitTo.BeTrue()
.PaymentMethods.Card.Click()
.Submit.ClickAndGo<CardPaymentPage>()
.CardNumber.IsVisible.WaitTo.BeTrue()
.Do(x =>
{
if (x.DebitCard.Exists(new SearchOptions { IsSafely = true, Timeout = TimeSpan.FromSeconds(1) }))
if (!switchFrame)
{
x.DebitCard.Click();
x
.Submit.ClickAndGo<CardPaymentPage>()
.CardNumber.IsVisible.WaitTo.BeTrue()
.Do(x =>
{
if (x.DebitCard.Exists(new SearchOptions { IsSafely = true, Timeout = TimeSpan.FromSeconds(1) }))
{
x.DebitCard.Click();
}
})
.CardNumber.Set(TestDataService.CreditCardNumber)
.Expiry.Set(TestDataService.CreditCardExpiratioDate)
.Cvc.Set(TestDataService.CreditCardCvc)
.Submit.Click();
}
else
{
x
.Submit.Click()
.SwitchToFrame<CardPaymentPage>(By.TagName("iframe"))
.CardNumber.IsVisible.WaitTo.BeTrue()
.Do(x =>
{
if (x.DebitCard.Exists(new SearchOptions { IsSafely = true, Timeout = TimeSpan.FromSeconds(1) }))
{
x.DebitCard.Click();
}
})
.CardNumber.Set(TestDataService.CreditCardNumber)
.Expiry.Set(TestDataService.CreditCardExpiratioDate)
.Cvc.Set(TestDataService.CreditCardCvc)
.Submit.Click();
}
})
.CardNumber.Set(TestDataService.CreditCardNumber)
.Expiry.Set(TestDataService.CreditCardExpiratioDate)
.Cvc.Set(TestDataService.CreditCardCvc)
.Submit.Click()
.SwitchToRoot<SveaPaymentFramePage>();
}

Expand All @@ -52,7 +78,7 @@ public static SveaPaymentFramePage PayWithTrustly(this SveaPaymentFramePage page
.PaymentMethods.Trustly.IsVisible.WaitTo.BeTrue()
.PaymentMethods.Trustly.Click()
.Submit.ClickAndGo<TrustlyPaymentPage>()
.Banks[0].IsVisible.WaitTo.BeTrue()
.Banks[0].IsVisible.WaitTo.Within(15).BeTrue()
.Banks[0].Click()
.Next.IsVisible.WaitTo.Within(60).BeTrue()
.Next.Click()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static SveaPaymentFramePage IdentifyEntity(this SveaPaymentFramePage page
}
}

public static SveaPaymentFramePage Pay(this SveaPaymentFramePage page, Checkout.Option checkout = Checkout.Option.Identification, Entity.Option entity = Entity.Option.Private, PaymentMethods.Option paymentMethod = PaymentMethods.Option.Card, string amount = null)
public static SveaPaymentFramePage Pay(this SveaPaymentFramePage page, Checkout.Option checkout = Checkout.Option.Identification, Entity.Option entity = Entity.Option.Private, PaymentMethods.Option paymentMethod = PaymentMethods.Option.Card, string amount = null, bool switchFrame = false)
{
switch (paymentMethod)
{
Expand Down Expand Up @@ -102,7 +102,7 @@ public static SveaPaymentFramePage Pay(this SveaPaymentFramePage page, Checkout.
{
default:
case PaymentMethods.Option.Card:
return page.PayWithCard();
return page.PayWithCard(switchFrame);

case PaymentMethods.Option.DirektBank:
return page.PayWithDirektBank();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void ChangeCountryAtCheckout(Product[] products)
.International.ZipCode.Set(TestDataService.SwedishZipCode)
.International.City.Set(TestDataService.SwedishCity)
.Submit.Click()
.Pay(Checkout.Option.Anonymous, Entity.Option.Private, PaymentMethods.Option.Card, null)
.Pay(Checkout.Option.Anonymous, Entity.Option.Private, PaymentMethods.Option.Card, null, switchFrame: true)
.PageUrl.Should.Within(TimeSpan.FromSeconds(60)).Contain("thankyou")
.SwitchToRoot<ThankYouPage>()
.ThankYou.IsVisible.WaitTo.BeTrue();
Expand Down

0 comments on commit f5a9bf9

Please sign in to comment.