Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions TransactionMobile.Maui.UiTests/Drivers/AppiumDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ private static void SetupAndroidDriver(AppiumLocalService appiumService) {
driverOptions.AddAdditionalAppiumOption("appPackage", "com.transactionprocessing.pos");
//driverOptions.AddAdditionalAppiumOption("forceEspressoRebuild", true);
driverOptions.AddAdditionalAppiumOption("enforceAppInstall", true);
driverOptions.AddAdditionalAppiumOption("uiautomator2ServerInstallTimeout", "40000");
//driverOptions.AddAdditionalAppiumOption("noSign", true);
//driverOptions.AddAdditionalAppiumOption("espressoBuildConfig",
// "{ \"additionalAppDependencies\": [ \"com.google.android.material:material:1.0.0\", \"androidx.lifecycle:lifecycle-extensions:2.1.0\" ] }");
Expand Down
5 changes: 2 additions & 3 deletions TransactionMobile.Maui.UiTests/Pages/BasePage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace TransactionMobile.Maui.UITests
{
using Common;
using OpenQA.Selenium;
using OpenQA.Selenium.Interactions;
using Shouldly;

public abstract class BasePage
Expand Down Expand Up @@ -41,8 +42,7 @@ public void WaitForPageToLeave(TimeSpan? timeout = null)
Should.NotThrow(() => this.WaitForNoElementByAccessibilityId(this.Trait), message);
}

public async Task<IWebElement> WaitForElementByAccessibilityId(String accessibilityId, TimeSpan? timeout = null)
{
public async Task<IWebElement> WaitForElementByAccessibilityId(String accessibilityId, TimeSpan? timeout = null) {
return await AppiumDriverWrapper.Driver.WaitForElementByAccessibilityId(accessibilityId, timeout);
}

Expand All @@ -63,7 +63,6 @@ public async Task WaitForToastMessage(String toastMessage)

public void HideKeyboard()
{
//AppiumDriverWrapper.Driver.HideKeyboard();
if (AppiumDriverWrapper.MobileTestPlatform == MobileTestPlatform.Android)
{
AppiumDriverWrapper.Driver.HideKeyboard();
Expand Down
39 changes: 33 additions & 6 deletions TransactionMobile.Maui.UiTests/Pages/Extenstions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ namespace TransactionMobile.Maui.UITests;
using OpenQA.Selenium;
using OpenQA.Selenium.Appium.Android;
using OpenQA.Selenium.Appium.iOS;
using OpenQA.Selenium.Appium.MultiTouch;
using OpenQA.Selenium.Interactions;
using Shouldly;

public static class Extenstions
Expand All @@ -21,21 +23,46 @@ public static class Extenstions
//{
// return driver.FindElementByClassName("androidx.appcompat.widget.AppCompatTextView");
//}

public static async Task<IWebElement> WaitForElementByAccessibilityId(this AppiumDriver driver,
String selector,
TimeSpan? timeout = null) {
IWebElement? element = null;
timeout ??= TimeSpan.FromSeconds(60);

await Retry.For(async () =>
{
element = driver.FindElement(MobileBy.AccessibilityId(selector));
element.ShouldNotBeNull();
await Retry.For(async () => {
for (int i = 0; i < 10; i++) {
driver.ScrollDown();
element = driver.FindElement(MobileBy.AccessibilityId(selector));
element.ShouldNotBeNull();
// All good so exit the loop
break;
}
});
return element;
}

public static void ScrollDown(this AppiumDriver driver)
{
//if pressX was zero it didn't work for me
int pressX = driver.Manage().Window.Size.Width / 2;
// 4/5 of the screen as the bottom finger-press point
int bottomY = driver.Manage().Window.Size.Height * 4 / 5;
// just non zero point, as it didn't scroll to zero normally
int topY = driver.Manage().Window.Size.Height / 8;
//scroll with TouchAction by itself
driver.Scroll(pressX, bottomY, pressX, topY);
}

/*
* don't forget that it's "natural scroll" where
* fromY is the point where you press the and toY where you release it
*/
public static void Scroll(this AppiumDriver driver, int fromX, int fromY, int toX, int toY)
{
TouchAction touchAction = new TouchAction(driver);
touchAction.LongPress(fromX, fromY).MoveTo(toX, toY).Release().Perform();
}

public static async Task WaitForNoElementByAccessibilityId(this AppiumDriver driver,
String selector,
TimeSpan? timeout = null)
Expand Down
2 changes: 1 addition & 1 deletion TransactionMobile.Maui.UiTests/Pages/LoginPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace TransactionMobile.Maui.UITests;
using System;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Interactions;

public class LoginPage : BasePage
{
Expand Down Expand Up @@ -78,7 +79,6 @@ public async Task EnterPassword(String password)

public async Task ClickLoginButton()
{
//this.HideKeyboard();
IWebElement element = await this.WaitForElementByAccessibilityId(this.LoginButton);
element.Click();
}
Expand Down
59 changes: 23 additions & 36 deletions TransactionMobile.Maui/Pages/LoginPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,58 +6,45 @@
Shell.NavBarIsVisible="False"
Shell.FlyoutItemIsVisible="True">
<ContentPage.Content>
<!-- Main structure-->
<VerticalStackLayout x:Name="MainLayout">
<!--Main image-->
<Image Source="loginimage.jpg" VerticalOptions="Start" Aspect="AspectFit"/>

<!-- Title-->
<Label Text="Log In" FontSize="34" HorizontalOptions="Center" FontAttributes="Bold" Padding="20,0,0,20"
<ScrollView>
<!-- Main structure-->
<VerticalStackLayout x:Name="MainLayout">
<!--Main image-->
<Image Source="loginimage.jpg" VerticalOptions="Start" Aspect="AspectFit"/>

<!-- Title-->
<Label Text="Log In" FontSize="34" HorizontalOptions="Center" FontAttributes="Bold" Padding="20,0,0,20"
AutomationId="LoginLabel"/>

<Frame HasShadow="True" Padding="25,50" Margin="10,0,10,10" VerticalOptions="CenterAndExpand"
<Frame HasShadow="True" Padding="25,50" Margin="10,0,10,10" VerticalOptions="CenterAndExpand"
CornerRadius="20" Opacity="0.9" BackgroundColor="#E5E9F0">
<VerticalStackLayout x:Name="SubLayout">
<VerticalStackLayout x:Name="SubLayout">

<Entry x:Name="UserNameEntry"
<Entry x:Name="UserNameEntry"
Placeholder="User name or email address"
AutomationId="UserNameEntry"
Style="{DynamicResource UserNameEntryStyle}"
Text="{Binding UserName}">
</Entry>
</Entry>

<Entry x:Name="PasswordEntry"
<Entry x:Name="PasswordEntry"
Placeholder="******"
AutomationId="PasswordEntry"
Style="{DynamicResource PasswordEntryStyle}"
Text="{Binding Password}">
</Entry>

<!--<HorizontalStackLayout x:Name="SwitchLayout">
<Label Text="Use Training Mode?"/>

<Switch x:Name="UseTrainingMode"
AutomationId="UseTrainingModeSwitch"/>
</HorizontalStackLayout>-->

<HorizontalStackLayout Margin="20"
Spacing="10">
<!--<Rectangle Fill="Red"
HeightRequest="30"
WidthRequest="30" />
<Label Text="Red"
FontSize="Large" />-->
<Label Text="Use Training Mode?" VerticalOptions="Center" HorizontalOptions="Start"/>
</Entry>
<HorizontalStackLayout Margin="20" Spacing="10">
<Label Text="Use Training Mode?" VerticalOptions="Center" HorizontalOptions="Start"/>

<Switch x:Name="UseTrainingMode" VerticalOptions="Center" HorizontalOptions="Start" AutomationId="UseTrainingModeSwitch"
<Switch x:Name="UseTrainingMode" VerticalOptions="Center" HorizontalOptions="Start" AutomationId="UseTrainingModeSwitch"
IsToggled="{Binding UseTrainingMode}"
/>
</HorizontalStackLayout>
</HorizontalStackLayout>

<Button Text="Continue" Style="{StaticResource StandardButton}" Command="{Binding LoginCommand}" AutomationId="LoginButton"/>
<!--<Label Grid.ColumnSpan="2" Grid.Row="3" Text="Forgot your password?" TextColor="{StaticResource P}" FontAttributes="Bold"/>-->
</VerticalStackLayout>
</Frame>
</VerticalStackLayout>
<Button Text="Continue" Style="{StaticResource StandardButton}" Command="{Binding LoginCommand}" AutomationId="LoginButton"/>
</VerticalStackLayout>
</Frame>
</VerticalStackLayout>
</ScrollView>
</ContentPage.Content>
</ContentPage>