add openhack files
This commit is contained in:
125
MobileApps/MyDriving/MyDriving.UITests/Pages/BasePage.cs
Normal file
125
MobileApps/MyDriving/MyDriving.UITests/Pages/BasePage.cs
Normal file
@ -0,0 +1,125 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for details.
|
||||
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using Xamarin.UITest;
|
||||
using Xamarin.UITest.Queries;
|
||||
using Xamarin.UITest.Android;
|
||||
using Xamarin.UITest.iOS;
|
||||
using Query = System.Func<Xamarin.UITest.Queries.AppQuery, Xamarin.UITest.Queries.AppQuery>;
|
||||
using System.Linq;
|
||||
|
||||
namespace MyDriving.UITests
|
||||
{
|
||||
public class BasePage
|
||||
{
|
||||
protected readonly IApp App;
|
||||
protected readonly bool OnAndroid;
|
||||
protected readonly bool OniOS;
|
||||
|
||||
protected Func<AppQuery, AppQuery> Trait;
|
||||
|
||||
protected BasePage()
|
||||
{
|
||||
App = AppInitializer.App;
|
||||
|
||||
OnAndroid = App.GetType() == typeof(AndroidApp);
|
||||
OniOS = App.GetType() == typeof(iOSApp);
|
||||
|
||||
InitializeCommonQueries();
|
||||
}
|
||||
|
||||
protected BasePage(Func<AppQuery, AppQuery> androidTrait, Func<AppQuery, AppQuery> iOSTrait)
|
||||
: this()
|
||||
{
|
||||
if (OnAndroid)
|
||||
Trait = androidTrait;
|
||||
if (OniOS)
|
||||
Trait = iOSTrait;
|
||||
|
||||
AssertOnPage(TimeSpan.FromSeconds(30));
|
||||
|
||||
App.Screenshot("On " + this.GetType().Name);
|
||||
}
|
||||
|
||||
protected BasePage(string androidTrait, string iOSTrait)
|
||||
: this(x => x.Marked(androidTrait), x => x.Marked(iOSTrait))
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the trait is still present. Defaults to no wait.
|
||||
/// </summary>
|
||||
/// <param name="timeout">Time to wait before the assertion fails</param>
|
||||
public void AssertOnPage(TimeSpan? timeout = default(TimeSpan?))
|
||||
{
|
||||
if (Trait == null)
|
||||
throw new NullReferenceException("Trait not set");
|
||||
|
||||
var message = "Unable to verify on page: " + this.GetType().Name;
|
||||
|
||||
if (timeout == null)
|
||||
Assert.IsNotEmpty(App.Query(Trait), message);
|
||||
else
|
||||
Assert.DoesNotThrow(() => App.WaitForElement(Trait, timeout: timeout), message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the trait is no longer present. Defaults to a two second wait.
|
||||
/// </summary>
|
||||
/// <param name="timeout">Time to wait before the assertion fails</param>
|
||||
protected void WaitForPageToLeave(TimeSpan? timeout = default(TimeSpan?))
|
||||
{
|
||||
if (Trait == null)
|
||||
throw new NullReferenceException("Trait not set");
|
||||
|
||||
timeout = timeout ?? TimeSpan.FromSeconds(2);
|
||||
var message = "Unable to verify *not* on page: " + this.GetType().Name;
|
||||
|
||||
Assert.DoesNotThrow(() => App.WaitForNoElement(Trait, timeout: timeout), message);
|
||||
}
|
||||
|
||||
public void NavigateTo(string tabName)
|
||||
{
|
||||
if (OnAndroid)
|
||||
{
|
||||
if (App.Query(_hamburger).Any())
|
||||
App.Tap(_hamburger);
|
||||
|
||||
App.Screenshot("Navigation Menu Open");
|
||||
int count = 0;
|
||||
while (!App.Query(tabName).Any() && count < 3)
|
||||
{
|
||||
App.ScrollDown(x => x.Class("NavigationMenuView"));
|
||||
count++;
|
||||
}
|
||||
}
|
||||
App.Tap(_tab(tabName));
|
||||
}
|
||||
|
||||
#region CommonPageActions
|
||||
|
||||
// Use this region to define functionality that is common across many or all pages in your app.
|
||||
// Eg tapping the back button of a page or selecting the tabs of a tab bar
|
||||
|
||||
Query _hamburger;
|
||||
Func<string, Query> _tab;
|
||||
|
||||
void InitializeCommonQueries()
|
||||
{
|
||||
if (OnAndroid)
|
||||
{
|
||||
_hamburger = x => x.Marked("Navigate up");
|
||||
_tab = name => x => x.Id("design_menu_item_text").Text(name);
|
||||
}
|
||||
|
||||
if (OniOS)
|
||||
{
|
||||
_tab = name => x => x.Class("UITabBarButtonLabel").Text(name);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for details.
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Xamarin.UITest;
|
||||
using Query = System.Func<Xamarin.UITest.Queries.AppQuery, Xamarin.UITest.Queries.AppQuery>;
|
||||
|
||||
namespace MyDriving.UITests
|
||||
{
|
||||
public class CurrentTripPage : BasePage
|
||||
{
|
||||
readonly Query RecordingButton;
|
||||
readonly string UseSimulatorButton = "Use Simulator";
|
||||
readonly Query TripTitleField;
|
||||
readonly Query SaveTripButton;
|
||||
|
||||
public CurrentTripPage ()
|
||||
: base("Current Trip", "Current Trip")
|
||||
{
|
||||
if (OnAndroid)
|
||||
{
|
||||
RecordingButton = x => x.Id("fab");
|
||||
TripTitleField = x => x.Class("EditText");
|
||||
SaveTripButton = x => x.Id("button1");
|
||||
}
|
||||
if (OniOS)
|
||||
{
|
||||
RecordingButton = x => x.Class("UIButton");
|
||||
SaveTripButton = x => x.Marked("OK");
|
||||
TripTitleField = x => x.Class("UITextField");
|
||||
}
|
||||
}
|
||||
|
||||
public CurrentTripPage StartRecordingTrip ()
|
||||
{
|
||||
App.Tap (RecordingButton);
|
||||
|
||||
System.Threading.Thread.Sleep(2500);
|
||||
|
||||
if (!App.Query(UseSimulatorButton).Any())
|
||||
{
|
||||
App.Tap(RecordingButton);
|
||||
}
|
||||
|
||||
App.Tap(UseSimulatorButton);
|
||||
|
||||
App.Screenshot ("Started recording trip");
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public CurrentTripPage StopRecordingTrip ()
|
||||
{
|
||||
System.Threading.Thread.Sleep (2500);
|
||||
App.Tap (RecordingButton);
|
||||
App.Screenshot("Stopped recording trip");
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public CurrentTripPage SaveTrip (string title)
|
||||
{
|
||||
App.ClearText (TripTitleField);
|
||||
App.EnterText (TripTitleField, title);
|
||||
App.DismissKeyboard ();
|
||||
|
||||
App.Screenshot ("Trip title entered");
|
||||
|
||||
App.Tap(SaveTripButton);
|
||||
App.Screenshot("Trip Saved!");
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace MyDriving.UITests
|
||||
{
|
||||
public class FacebookLoginPage : BasePage
|
||||
{
|
||||
public FacebookLoginPage()
|
||||
:base(x => x.WebView(), x => x.WebView())
|
||||
{
|
||||
}
|
||||
|
||||
public void Login()
|
||||
{
|
||||
App.WaitForElement(c => c.Css("INPUT._56bg._4u9z._5ruq")
|
||||
, timeout:TimeSpan.FromSeconds(20)
|
||||
, timeoutMessage:"Facebook login UI not displayed");
|
||||
|
||||
App.EnterText(c => c.Css("INPUT._56bg._4u9z._5ruq"), "scott_kdnkrdr_guthrie@tfbnw.net");
|
||||
App.DismissKeyboard();
|
||||
App.EnterText(c => c.Css("#u_0_1"), "admin1");
|
||||
App.DismissKeyboard();
|
||||
|
||||
App.Screenshot("Entered Facebook Credentials");
|
||||
|
||||
App.Tap(c => c.Css("#u_0_5"));
|
||||
|
||||
try
|
||||
{
|
||||
//some OS opt for saving passwords from webviews. This catches that case
|
||||
App.WaitForElement("Do you want the browser to remember this password?", timeout: TimeSpan.FromSeconds(5));
|
||||
App.Tap("Not now");
|
||||
}
|
||||
catch { }
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
39
MobileApps/MyDriving/MyDriving.UITests/Pages/LoginPage.cs
Normal file
39
MobileApps/MyDriving/MyDriving.UITests/Pages/LoginPage.cs
Normal file
@ -0,0 +1,39 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for details.
|
||||
|
||||
using Query = System.Func<Xamarin.UITest.Queries.AppQuery, Xamarin.UITest.Queries.AppQuery>;
|
||||
|
||||
namespace MyDriving.UITests
|
||||
{
|
||||
public class LoginPage : BasePage
|
||||
{
|
||||
string LoginWithFacebookButton;
|
||||
string SkipAuthenticationButton;
|
||||
|
||||
public LoginPage ()
|
||||
: base (c => c.Marked ("button_twitter"), c => c.Marked ("LoginWithTwitter"))
|
||||
{
|
||||
if (OnAndroid) {
|
||||
LoginWithFacebookButton = "button_facebook";
|
||||
SkipAuthenticationButton = "button_skip";
|
||||
}
|
||||
|
||||
if (OniOS) {
|
||||
LoginWithFacebookButton = "LoginWithFacebook";
|
||||
SkipAuthenticationButton = "Skip Auth";
|
||||
}
|
||||
}
|
||||
|
||||
public void LoginWithFacebook()
|
||||
{
|
||||
App.Tap (LoginWithFacebookButton);
|
||||
App.Screenshot("Selecting Facebook Login");
|
||||
}
|
||||
|
||||
public void SkipAuthentication()
|
||||
{
|
||||
App.Tap (SkipAuthenticationButton);
|
||||
App.Screenshot ("Authentication Skipped");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using Query = System.Func<Xamarin.UITest.Queries.AppQuery, Xamarin.UITest.Queries.AppQuery>;
|
||||
|
||||
namespace MyDriving.UITests
|
||||
{
|
||||
public class PastTripDetailPage : BasePage
|
||||
{
|
||||
readonly Query TripProgressSlider;
|
||||
|
||||
public PastTripDetailPage()
|
||||
: base(x => x.Marked("stats"), x => x.Class("UISlider"))
|
||||
{
|
||||
if (OniOS)
|
||||
{
|
||||
TripProgressSlider = x => x.Class("UISlider");
|
||||
}
|
||||
if (OnAndroid)
|
||||
{
|
||||
TripProgressSlider = x => x.Id("trip_progress");
|
||||
}
|
||||
}
|
||||
|
||||
public PastTripDetailPage MoveTripSlider()
|
||||
{
|
||||
App.SetSliderValue(TripProgressSlider, 250);
|
||||
App.Screenshot("Trip Slider at 25%");
|
||||
|
||||
App.SetSliderValue(TripProgressSlider, 750);
|
||||
App.Screenshot("Trip Slider at 75%");
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public PastTripDetailPage ClickTripSliderEndpoints()
|
||||
{
|
||||
if (OniOS)
|
||||
{
|
||||
App.Tap(x => x.Text("A"));
|
||||
App.Screenshot("Tapped A Endpoint");
|
||||
|
||||
App.Tap(x => x.Text("B"));
|
||||
App.Screenshot("Tapped B Endpoint");
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,72 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for details.
|
||||
|
||||
using System;
|
||||
using Query = System.Func<Xamarin.UITest.Queries.AppQuery, Xamarin.UITest.Queries.AppQuery>;
|
||||
|
||||
namespace MyDriving.UITests
|
||||
{
|
||||
public class PastTripsPage : BasePage
|
||||
{
|
||||
readonly Query RefreshView;
|
||||
readonly Func<string, Query> PastTripCell;
|
||||
|
||||
public PastTripsPage()
|
||||
: base (x => x.Marked("Past Trips"), x => x.Class("UINavigationItemView").Marked("Past Trips"))
|
||||
{
|
||||
if (OniOS)
|
||||
{
|
||||
RefreshView = x => x.Class("UITableView");
|
||||
PastTripCell = (arg) => x => x.Marked(arg).Parent().Class("TripTableViewCellWithImage");
|
||||
}
|
||||
if (OnAndroid)
|
||||
{
|
||||
RefreshView = x => x.Id("content_frame");
|
||||
}
|
||||
}
|
||||
|
||||
public PastTripsPage PullToRefresh ()
|
||||
{
|
||||
App.WaitForElement(RefreshView);
|
||||
var coords = App.Query(RefreshView)[0].Rect;
|
||||
if (OniOS)
|
||||
App.DragCoordinates(coords.CenterX, coords.Y + 75, coords.CenterX, coords.CenterY);
|
||||
if (OnAndroid)
|
||||
App.DragCoordinates(coords.CenterX, coords.Y, coords.CenterX, coords.CenterY);
|
||||
|
||||
App.Screenshot("Pulled view to refresh");
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public void NavigateToPastTripsDetail (string title)
|
||||
{
|
||||
if (OnAndroid)
|
||||
{
|
||||
App.ScrollDownTo(title);
|
||||
App.Screenshot("Selecting past trip: " + title);
|
||||
App.Tap(title);
|
||||
}
|
||||
if (OniOS)
|
||||
{
|
||||
App.ScrollDownTo(PastTripCell(title));
|
||||
App.Screenshot("Selecting past trip: " + title);
|
||||
App.Tap(PastTripCell(title));
|
||||
}
|
||||
}
|
||||
|
||||
public PastTripsPage ClickTripSliderEndpoints()
|
||||
{
|
||||
if (OniOS)
|
||||
{
|
||||
App.Tap(x => x.Text("A"));
|
||||
App.Screenshot("Tapped A Endpoint");
|
||||
|
||||
App.Tap(x => x.Text("B"));
|
||||
App.Screenshot("Tapped B Endpoint");
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
67
MobileApps/MyDriving/MyDriving.UITests/Pages/ProfilePage.cs
Normal file
67
MobileApps/MyDriving/MyDriving.UITests/Pages/ProfilePage.cs
Normal file
@ -0,0 +1,67 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for details.
|
||||
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using Xamarin.UITest;
|
||||
|
||||
using Query = System.Func<Xamarin.UITest.Queries.AppQuery, Xamarin.UITest.Queries.AppQuery>;
|
||||
|
||||
namespace MyDriving.UITests
|
||||
{
|
||||
public class ProfilePage : BasePage
|
||||
{
|
||||
readonly Query FuelConsumptionField;
|
||||
readonly Query DistanceField;
|
||||
readonly Query SettingsTab;
|
||||
|
||||
public ProfilePage ()
|
||||
: base (x => x.Marked("profile_image"), x => x.Raw("* {text CONTAINS 'Driving Skills: '}"))
|
||||
{
|
||||
if (OnAndroid)
|
||||
{
|
||||
FuelConsumptionField = x => x.Id("text_fuel_consumption");
|
||||
DistanceField = x => x.Id("text_distance");
|
||||
}
|
||||
if (OniOS)
|
||||
{
|
||||
SettingsTab = x => x.Id("tab_Settings.png");
|
||||
FuelConsumptionField = x => x.Class("ProfileStatCell").Descendant().Marked("Fuel Consumption").Sibling();
|
||||
DistanceField = x => x.Class("ProfileStatCell").Descendant().Marked("Total Distance").Sibling();
|
||||
}
|
||||
}
|
||||
|
||||
public ProfilePage CheckFuelMetric(bool metric)
|
||||
{
|
||||
App.ScrollDownTo(FuelConsumptionField);
|
||||
var fuelText = App.Query(FuelConsumptionField)[0].Text;
|
||||
App.Screenshot("Verifying fuel units correct");
|
||||
|
||||
var expectedUnits = metric ? "l" : "gal";
|
||||
StringAssert.Contains(expectedUnits, fuelText, message:"Couldnt verify fuel units");
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public ProfilePage CheckDistanceMetric(bool metric)
|
||||
{
|
||||
App.ScrollDownTo(DistanceField);
|
||||
var distanceText = App.Query(DistanceField)[0].Text;
|
||||
App.Screenshot("Verifying distance units correct");
|
||||
|
||||
var expectedUnits = metric ? "km" : "miles";
|
||||
StringAssert.Contains(expectedUnits, distanceText, message: "Couldnt verify distance units");
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public void NavigateToSettings()
|
||||
{
|
||||
if (OnAndroid)
|
||||
return;
|
||||
|
||||
App.Tap(SettingsTab);
|
||||
App.Screenshot("Tapped Settings Tab");
|
||||
}
|
||||
}
|
||||
}
|
73
MobileApps/MyDriving/MyDriving.UITests/Pages/SettingsPage.cs
Normal file
73
MobileApps/MyDriving/MyDriving.UITests/Pages/SettingsPage.cs
Normal file
@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using Xamarin.UITest;
|
||||
using Query = System.Func<Xamarin.UITest.Queries.AppQuery, Xamarin.UITest.Queries.AppQuery>;
|
||||
|
||||
namespace MyDriving.UITests
|
||||
{
|
||||
public class SettingsPage : BasePage
|
||||
{
|
||||
readonly Func<string, Query> CheckBox;
|
||||
readonly Query SettingsTab;
|
||||
|
||||
public SettingsPage()
|
||||
: base ("Settings", "Settings")
|
||||
{
|
||||
if (OniOS)
|
||||
{
|
||||
SettingsTab = x => x.Class("UINavigationItemButtonView").Marked("Settings");
|
||||
}
|
||||
if (OnAndroid)
|
||||
{
|
||||
CheckBox = (arg) => x => x.Marked(arg).Parent(0).Sibling().Descendant().Id("checkbox");
|
||||
}
|
||||
}
|
||||
|
||||
public SettingsPage SetDistanceSetting()
|
||||
{
|
||||
if (OnAndroid)
|
||||
{
|
||||
App.Tap(CheckBox("Metric Distance"));
|
||||
App.Screenshot("Using Metric Distances");
|
||||
}
|
||||
if (OniOS)
|
||||
{
|
||||
App.Tap("Distance");
|
||||
App.Tap("Metric (km)");
|
||||
App.Screenshot("Using Metric Distances");
|
||||
|
||||
App.Tap(SettingsTab);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public SettingsPage SetCapacitySetting()
|
||||
{
|
||||
if (OnAndroid)
|
||||
{
|
||||
App.Tap(CheckBox("Metric Units"));
|
||||
App.Screenshot("Using Metric Capacity");
|
||||
}
|
||||
if (OniOS)
|
||||
{
|
||||
App.Tap("Capacity");
|
||||
App.Tap("Metric (liters)");
|
||||
App.Screenshot("Using Metric Capacity");
|
||||
|
||||
App.Tap(SettingsTab);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
new public void NavigateTo(string marked)
|
||||
{
|
||||
if (OnAndroid)
|
||||
base.NavigateTo(marked);
|
||||
|
||||
if (OniOS)
|
||||
App.Tap("Back");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
9
MobileApps/MyDriving/MyDriving.UITests/Pages/TabPage.cs
Normal file
9
MobileApps/MyDriving/MyDriving.UITests/Pages/TabPage.cs
Normal file
@ -0,0 +1,9 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for details.
|
||||
|
||||
namespace MyDriving.UITests
|
||||
{
|
||||
public class TabPage
|
||||
{
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using Xamarin.UITest;
|
||||
using Query = System.Func<Xamarin.UITest.Queries.AppQuery, Xamarin.UITest.Queries.AppQuery>;
|
||||
|
||||
namespace MyDriving.UITests
|
||||
{
|
||||
public class TripSummaryPage : BasePage
|
||||
{
|
||||
public TripSummaryPage()
|
||||
: base("Trip Summary", "Trip Summary")
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user