public void BasicFahrenheitSetup() { // Let something load before proceeding app.WaitForElement(x => x.Id("JunctionTemperatureLabel")); app.Screenshot("Initial launch"); app.SetSliderValue(x => x.Class("UISlider"), 12); app.SetSliderValue(x => x.Class("UISlider").Index(1), 5); // Have to scroll down on small screens to make lower views accessible app.ScrollDown(withinMarked: "CalcScrollView"); app.SetSliderValue(x => x.Class("UISlider").Index(2), 0.5); app.Screenshot("Sliders set for 5V from 12V at 0.5A"); app.ScrollUp(withinMarked: "CalcScrollView"); app.SetOrientationLandscape(); app.Screenshot("Setup in landscape"); app.SetOrientationPortrait(); app.Tap(x => x.Id("hamburger.png")); app.Screenshot("Opened settings"); app.Tap(x => x.Marked("Fahrenheit (°F)")); app.Screenshot("Tapped on view with class: UILabel marked: Fahrenheit (°F)"); app.SwipeRightToLeft(); app.Screenshot("Swiped left"); app.WaitForElement(x => x.Id("JunctionTemperatureLabel")); var temperatureF = app.Query(x => x.Id("JunctionTemperatureLabel")); Assert.IsTrue(temperatureF[0].Label.Equals("JUNCTION TEMP: 221.9 ˚F")); }
public void RunUnitTests() { //app.Repl(); var appName = GetAppName(); Console.WriteLine(appName); app.Tap(c => c.Marked("Run Everything")); app.WaitFor(() => app.Query(a => a.Class("UITableViewLabel")).SingleOrDefault(c => c.Label.Contains(" test cases, Runnable")) == null); var labels = app.Query(c => c.Class("UITableViewLabel")); var resultLabel = labels.SingleOrDefault(l => l.Label.Contains("Success!")); Console.WriteLine(string.Empty); Console.WriteLine("Test Results:"); app.Tap(c => c.Marked(appName)); app.WaitForNoElement(a => a.Class("UITableViewLabel").Marked("Options")); Assert.IsNotNull(resultLabel); }
public static AppResult DetailPage(this iOSApp app) { if (app.Query(q => q.Raw("view:'UILayoutContainerView'")).Length == 3) { // iPad SplitView Landscape return(app.Query(q => q.Raw("view:'UILayoutContainerView'"))[2]); } return(app.Query(q => q.Raw("*"))[0]); }
public void CreditCardNumber_ToShort_DisplayErrorMessage() { // Arrange - Nothing to do because the queries have already been initialized. // Act _app.EnterText(EditTextView, new string('9', 15)); _app.Tap(ValidateButton); // Assert AppResult[] result = _app.Query(ShortErrorMessage); Assert.IsTrue(result.Any(), "The error message is not being displayed."); }
public void WhenTappedOnTheInfoButtonShowInformationMessage() { app.Tap("Show Info"); app.Screenshot("Before messagebar"); app.WaitForElement(e => e.Id("MessageBar")); app.Screenshot("Messagebar dispalyed"); var title = app.Query(e => e.Id("MessageBar").Invoke("Title")).FirstOrDefault(); var text = app.Query(e => e.Id("MessageBar").Invoke("Description")).FirstOrDefault(); var type = app.Query(e => e.Id("MessageBar").Invoke("MessageType")).FirstOrDefault(); Assert.AreEqual("Info", title); Assert.AreEqual("This is information", text); Assert.AreEqual(type, 2); }
public void TapRandomButtonsTest() { var rand = new Random(); for (var i = 0; i < 10; i++) { var buttons = _app.Query(c => c.Button()).ToArray(); if (!buttons.Any()) { break; } try { _app.Tap(c => c.Button().Index(rand.Next(0, buttons.Length - 1))); } catch { // Fail silently, this is probably due to the number of buttons on the page being reduced between // the app.Query() and the app.Tap(). } var word = i == 0 ? "a" : "another"; _app.Screenshot($"Tapped {word} random button"); Thread.Sleep(3000); // This should allow any animations to complete in most cases } }
static bool MaybeGetLayerProperty <T> (iOSApp app, string query, string property, out object result) { try { result = app.Query(q => q.Raw(query).Invoke("layer").Invoke(property).Value <T> ()).First(); } catch { result = null; return(false); } return(true); }
private string GetTextFieldText(string textFieldAccessibilityId) { var result = string.Empty; if (app.Query(c => c.Id(textFieldAccessibilityId)).FirstOrDefault() is AppResult matchedTextField) { result = matchedTextField.Text; } return(result); }
public static bool DragFromToForElement(this iOSApp app, int scrollNumberLimit, Func <AppQuery, AppQuery> query, float xStart, float yStart, float xEnd, float yEnd) { int numberOfScrolls = 0; // Element exists if (app.Query(query).Length > 0) { return(true); } while (app.Query(query).Length == 0) { DragFromTo(app, xStart, yStart, xEnd, yEnd); if (numberOfScrolls > scrollNumberLimit) { return(false); } numberOfScrolls++; } // Element found return(true); }
string GetTitle() { var titleQuery = App switch { iOSApp iOSApp => iOSApp.Query(x => x.Class("UILabel").Marked(PageTitleConstants.OpportunityDetailPage)), AndroidApp androidApp => androidApp.Query(x => x.Class("AppCompatTextView").Marked(PageTitleConstants.OpportunityDetailPage)), _ => throw new NotSupportedException(), }; return(titleQuery?.FirstOrDefault()?.Text); }
string GetTitle(int timeoutInSeconds = 60) { App.WaitForElement(_pageTitleText, "Could Not Retrieve Page Title", TimeSpan.FromSeconds(timeoutInSeconds)); var titleQuery = App switch { iOSApp iosApp => iosApp.Query(x => x.Class("UILabel").Marked(_pageTitleText)), AndroidApp androidApp => androidApp.Query(x => x.Class("AppCompatTextView").Marked(_pageTitleText)), _ => throw new NotSupportedException(), }; return(titleQuery.First().Text); }
public void WhenIPickThanosAndGamoraThanosShouldWin() { app.WaitForElement("Batman"); app.Tap("Gamora"); app.Tap("Thanos"); app.Tap("Fight"); var resultLabel = app.Query("ResultLabel").First(); Assert.AreEqual("Thanos wins", resultLabel.Text); }
public void BeforeEachTest() { var introButtonVisible = app.Query(MenuIntroButton).Any(); if (introButtonVisible) { app.Tap(MenuIntroButton); } }
public void HappyPath() { app.WaitForElement(StatusLabel); app.WaitForElement(LoginButton); app.Screenshot("App loaded."); Assert.AreEqual(app.Query(StatusLabel).FirstOrDefault().Text, "Gigya initialized with domain: us1.gigya.com"); app.Tap(LoginButton); app.WaitForElement(GigyaWebView); app.Screenshot("Login activated."); app.Tap(CancelButton); app.WaitForElement(LoginButton); app.Screenshot("Login cancelled."); }
public static int IndexForElementWithText(this iOSApp app, Func <AppQuery, AppQuery> query, string text) { var elements = app.Query(query); int index = 0; for (int i = 0; i < elements.Length; i++) { string labelText = elements[i].Label; if (labelText == (text)) { index = i; break; } index++; } return(index == elements.Length ? -1 : index); }
public void ClickAddButtonAddsOneItem(string param) { Func <AppQuery, AppQuery> addButton = c => c.Button("addButton"); Func <AppQuery, AppQuery> tableCells = c => c.Class("UITableViewCell"); Func <AppQuery, AppQuery> detailView = c => c.Marked("Detail view content goes here"); Func <AppQuery, AppQuery> masterButton = c => c.Button("Master"); AppResult[] results = app.Query(detailView); if (results.Any()) { // Detail view is show first by iPad. app.Tap(masterButton); } app.Tap(addButton); results = app.WaitForElement(tableCells); app.Screenshot("New item added."); Assert.AreEqual(1, results.Length); }
public void EnterText() { //Arrange string typedText = "Hello world!"; string retrievedText; //Act app.Tap(MyEntry); app.ClearText(); app.Screenshot("Entry Tapped"); app.EnterText(typedText); app.DismissKeyboard(); app.Screenshot($"Entered Text: {typedText}"); //Assert retrievedText = app.Query(MyLabel).FirstOrDefault()?.Text; Assert.AreEqual(typedText, retrievedText, "The typed text does not match the text displayed on the screen"); }
public void CrawlDevices() { app.Screenshot("Login"); app.Tap(b => b.Button("Local")); app.EnterText("Hestia"); app.Screenshot("Server connect"); app.Tap(t => t.Text("Enter IP")); app.EnterText("94.212.164.28"); app.Tap(t => t.Text("Connect")); app.Screenshot("Devices"); app.Tap(b => b.Button("Edit")); app.Screenshot("Devices edit mode"); app.Tap(i => i.Id("AddDeviceIcon")); app.Screenshot("New device manufacturer"); app.Tap(t => t.Text("mock")); app.Screenshot("New device type"); app.Tap(t => t.Text("lock")); app.Screenshot("New device properties"); var l = app.Query(t => t.Text("NAME")); app.TapCoordinates(l[1].Rect.CenterX, l[1].Rect.CenterY + 20); app.EnterText("TestLock"); l = app.Query(t => t.Text("IP")); app.TapCoordinates(l[1].Rect.CenterX, l[1].Rect.CenterY + 20); app.EnterText("0.0.0.0"); app.Tap(b => b.Button("Save")); app.Screenshot("Added device"); app.Tap(t => t.Text("TestLock")); app.Screenshot("Device activators"); app.Tap(c => c.Class("UISwitch")); app.Tap(t => t.Text("Devices")); app.Tap(b => b.Button("Edit")); app.Tap(t => t.Text("TestLock")); app.Screenshot("Edit device"); l = app.Query(t => t.Text("TestLock")); app.TapCoordinates(l[0].Rect.CenterX, l[0].Rect.CenterY); app.EnterText("UITestLock"); app.Tap(b => b.Button("Save")); app.WaitForElement(t => t.Text("UITestLock")); l = app.Query(t => t.Text("UITestLock")); app.TapCoordinates(l[0].Rect.X, l[0].Rect.CenterY); app.Screenshot("Delete device"); app.TapCoordinates(l[0].Rect.Width - 1, l[0].Rect.CenterY); app.Tap(b => b.Button("Done")); }
public void B_Login() { Thread.Sleep(20000); app.SwipeRightToLeft(); app.SwipeRightToLeft(); app.SwipeRightToLeft(); Thread.Sleep(7000); app.Tap("I’m already a member"); Thread.Sleep(3000); app.Tap(x => x.TextField().Index(0)); app.EnterText(EmailFinal); app.Tap(x => x.TextField().Index(1)); app.EnterText("magicA123"); app.DismissKeyboard(); app.Tap("Sign me in!"); Thread.Sleep(20000); var isDia = app.Query("Continue").Any(); if (isDia == true) { app.Tap("Not now"); } var isDiaSec = app.Query(x => x.Id("icon_security")).Any(); if (isDiaSec == true) { app.Tap("I'll skip this"); } Console.Write("--- Login Success ---"); Thread.Sleep(3000); Details(); Baby(); History(); FeaturedRewards(); GetMorePoints(); ParentsHub(); Notifications(); Logout(); Console.Write("--- UI TEST AUTOMATION SUCCESS ---"); }
public void LikeLoop() { // Run infinite loop while (true) { var all = app.Query(q => q.Class("WKWebView").Css("*")); var hashtags = new List <string> (); // Search for hashtag foreach (var element in all) { if (!string.IsNullOrEmpty(element.TextContent) && element.Class == "_ezgzd") { var regex = new Regex(@"(?<=#)\w+"); var matches = regex.Matches(element.TextContent); foreach (Match m in matches) { hashtags.Add(m.Value); } } } // Search for the like button foreach (var element in all) { if (element.Class.Contains("coreSpriteHeartOpen")) { // Tap the like button app.TapCoordinates(element.Rect.CenterX, element.Rect.CenterY); // Capture a screenshot var imageFileInfo = app.Screenshot(DateTime.Now.ToString()); CustomVisionResponse imagePrediction = null; try { // Analyze the image with Microsoft Custom Vision var predictionRequestTask = MakePredictionRequest(imageFileInfo.FullName); predictionRequestTask.Wait(); // Save predictions imagePrediction = predictionRequestTask.Result; } catch (Exception ex) { Console.WriteLine($"Failed to get image ML details: {ex.Message}"); } finally { File.Delete(imageFileInfo.FullName); } try { // Report results: hashtags + ML predictions + metadata to AWS ReportLikeToAWS(imagePrediction, hashtags).Wait(); } catch (Exception ex) { Console.WriteLine($"Failed to report like to AWS: {ex.Message}"); } break; } } app.ScrollDown(); } }
public void ViewIsDisplayed() { // Example of Invoking selectRow in the native UIPickerView to set the value to the 4th row (0-based array) var invokingHere = app.Query(e => e.Id("PizzaPicker").Index(0).Invoke("selectRow", 3, "inComponent", 3, "animated", true)); }
public void TestCase() { var result = _app.Query(x => x.Text("Evolve")); Assert.IsNotNull(result); }