Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using NUnit.Framework;
- using System;
- using Xamarin.UITest;
- using Xamarin.UITest.Android;
- using Xamarin.UITest.Queries;
- using System.Threading;
- namespace AutoSage
- {
- [TestFixture()]
- public class Test
- {
- AndroidApp app;
- [SetUp]
- public void SetUp()
- {
- app = ConfigureApp.Android
- .ApiKey("YOUR API KEY")
- .ApkFile(@"PATH TO APK")
- .StartApp();
- }
- [Test]
- public void A_Login()
- {
- Login();
- }
- [Test]
- public void B_AddContact()
- {
- Login();
- AddContact();
- }
- [Test]
- public void C_NewInvoice()
- {
- Login();
- AddContact();
- NewInvoice();
- }
- public void Login()
- {
- //Wait for screen to load and take screenshot
- Thread.Sleep(9000);
- app.Screenshot("When I am logged into the app");
- //Tap Login on main screen
- AppResult mainLogin = app.Query(x => x.Id("NoResourceEntry-42").Raw("webView css:'.UILink'"))[1];
- app.TapCoordinates(mainLogin.Rect.CenterX, mainLogin.Rect.CenterY);
- Thread.Sleep(7000);
- app.Screenshot("And I clicked Login");
- //Sign in with google
- while (app.Query(x => x.Id("NoResourceEntry-42").Raw("webView css:'.auth_additional'")).Length == 0)
- app.ScrollDown();
- AppResult googleLogin = app.Query(x => x.Id("NoResourceEntry-42").Raw("webView css:'.UILink'"))[1];
- //Tap google sign in
- app.TapCoordinates(googleLogin.Rect.CenterX, googleLogin.Rect.CenterY);
- app.Screenshot("Then I click 'Sign in with google'");
- //Enter email
- AppResult emailEntry = app.Query(x => x.Id("NoResourceEntry-42").Raw("webView css:'#Email'"))[0];
- app.TapCoordinates(emailEntry.Rect.CenterX, emailEntry.Rect.CenterY);
- app.EnterText("test@gmail.com");
- app.Screenshot("Then I enter in my email address");
- //Enter Password
- Thread.Sleep(1000);
- while (app.IsItThere(x => x.Id("NoResourceEntry-42").Raw("webView css:'#Passwd'")) == false)
- {
- app.ScrollDown();
- }
- AppResult pwdEntry = app.Query(x => x.Id("NoResourceEntry-42").Raw("webView css:'#Passwd'"))[0];
- app.TapCoordinates(pwdEntry.Rect.CenterX, pwdEntry.Rect.CenterY);
- Thread.Sleep(1000);
- app.EnterText("test");
- Thread.Sleep(2000);
- app.Screenshot("Then I enter in my password");
- //Tap Sign In
- while (app.IsItThere(x => x.Id("NoResourceEntry-42").Raw("webView css:'#signIn'")) == false)
- {
- app.ScrollDown();
- }
- app.ScrollDownEnough(x => x.Id("NoResourceEntry-42").Raw("webView css:'#signIn'"));
- app.WaitForThenTap(
- x => x.Id("NoResourceEntry-42").Raw("webView css:'#signIn'"),
- "Then I press the Sign In button");
- if (app.IsItThere(x => x.Text("Confirm")) == true)
- {
- app.WaitForElement(x => x.Text("Never"));
- app.Tap(x => x.Text("Never"));
- }
- //Wait for pin screen & allow slower devices to catch up
- app.WaitForElement(x => x.Class("sage.sageone.sageonemobile.android.view.PinButtonRenderer"),"Timed out waiting for PIN screen", new TimeSpan (0, 0, 0, 10), null, null);
- app.Screenshot("Then I am asked to Enter my pin number");
- //Enter Pin
- AppResult pinButton = app.Query(x => x.Class("sage.sageone.sageonemobile.android.view.PinButtonRenderer"))[0];
- app.TapCoordinates(pinButton.Rect.CenterX, pinButton.Rect.CenterY);
- app.Screenshot("Then I enter my PIN");
- app.TapCoordinates(pinButton.Rect.CenterX, pinButton.Rect.CenterY);
- app.Screenshot("Then I enter my PIN");
- app.TapCoordinates(pinButton.Rect.CenterX, pinButton.Rect.CenterY);
- app.Screenshot("Then I enter my PIN");
- app.TapCoordinates(pinButton.Rect.CenterX, pinButton.Rect.CenterY);
- app.Screenshot("Then I enter my PIN");
- app.TapCoordinates(pinButton.Rect.CenterX, pinButton.Rect.CenterY);
- app.Screenshot("Then I enter my PIN");
- app.TapCoordinates(pinButton.Rect.CenterX, pinButton.Rect.CenterY);
- app.Screenshot("Then I enter my PIN");
- app.TapCoordinates(pinButton.Rect.CenterX, pinButton.Rect.CenterY);
- app.Screenshot("Then I enter my PIN");
- app.TapCoordinates(pinButton.Rect.CenterX, pinButton.Rect.CenterY);
- app.Screenshot("Then I enter my PIN");
- //to keep screen alive
- Thread.Sleep(4000);
- app.TapCoordinates(10, 10);
- //And logged in
- app.WaitForElement(x => x.Text("New Contact"), "Timed out logging in", new TimeSpan(0, 0, 25), null, null);
- app.Screenshot("And I am logged in");
- }
- public void AddContact()
- {
- //Add Contact
- app.WaitForThenTap(
- x => x.Text("New Contact"),
- "Then I add a new contact");
- //find coordinates and tap to give focus, then enter text.
- AppResult firstName = app.Query(x => x.Class("xamarin.forms.platform.android.EntryEditText"))[0];
- app.TapCoordinates(firstName.Rect.CenterX, firstName.Rect.CenterY);
- app.EnterText("John");
- app.Screenshot("Then I enter the first name");
- //find coordinates and tap to give focus, then enter text.
- AppResult lastName = app.Query(x => x.Class("xamarin.forms.platform.android.EntryEditText"))[1];
- app.TapCoordinates(lastName.Rect.CenterX, lastName.Rect.CenterY);
- app.EnterText("Doe");
- app.Screenshot("Then I enter the last name");
- app.Tap(x => x.Text("Save"));
- app.Screenshot("Then I save the contact");
- app.WaitForElement(x => x.Text("Contact Details"));
- app.Tap(x => x.Text("Contact Details"));
- app.Screenshot("Then I navigate back to the home screen");
- }
- public void NewInvoice()
- {
- // new invoice
- app.WaitForThenTap(x => x.Text("New Invoice"), "Then I create a new invoice");
- AppResult contactName = app.Query(x => x.Class("xamarin.forms.platform.android.EntryEditText"))[0];
- app.TapCoordinates(contactName.Rect.CenterX, contactName.Rect.CenterY);
- app.EnterText("j");
- app.Screenshot("Then I start to type the customer's name");
- app.WaitForThenTap(x => x.Text("John Doe"), "Then I tap the contacts name");
- app.WaitForThenTap(x => x.Text("Add Item"), "Then I add an item");
- AppResult addItem = app.Query(x => x.Class("xamarin.forms.platform.android.EntryEditText"))[0];
- app.TapCoordinates(addItem.Rect.CenterX, addItem.Rect.CenterY);
- Thread.Sleep(1000);
- app.EnterText("Awesome Description");
- app.Screenshot("Then I enter an item");
- app.WaitForThenTap(x => x.Text("Save"), "Then I save the item");
- app.WaitForThenTap(x => x.Text("Save"), "Then I save the invoice");
- app.WaitForThenTap(x => x.Id("action_bar_title"), "Then I navigate back to the home screen");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement