private static void SwipeUp(IOSDriver <IOSElement> driver, AppiumWebElement element) { string script = "mobile: swipe"; Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("direction", "up"); parameters.Add("element", element.Id); driver.ExecuteScript(script, parameters); }
public void CanActivateViaScriptAppTest() { //Activate an app to foreground Assert.DoesNotThrow(() => _driver.ExecuteScript("mobile: activateApp", new Dictionary <string, string> { { "bundleId", IosTestAppBundleId } })); //Verify the expected app was activated Assert.DoesNotThrow(() => _driver.FindElementByAccessibilityId(IosTestAppElement)); }
public void AppiumTestMethod() { Dictionary <String, Object> pars = new Dictionary <String, Object>(); String res; try { reportiumClient.testStart("Image Injection Assignment", new TestContextTags("assignment4", "image")); // write your code here reportiumClient.stepStart("Start the app and upload the image"); try { // close the calendar if open to verify that starting from fresh app pars.Add("name", "RealTimeFilter"); driver.ExecuteScript("mobile:application:close", pars); } catch (Exception e) { Trace.Write(e.StackTrace); Trace.WriteLine(" "); } try { pars.Clear(); pars.Add("name", "RealTimeFilter"); driver.ExecuteScript("mobile:application:open", pars); } catch (Exception e) { // unable to start the app, probably because it isn't installed pars.Clear(); pars.Add("file", "PUBLIC:ImageInjection\\RealTimeFilter.ipa"); pars.Add("sensorInstrument", "sensor"); driver.ExecuteScript("mobile:application:install", pars); pars.Clear(); pars.Add("name", "RealTimeFilter"); driver.ExecuteScript("mobile:application:open", pars); } driver.Context = "NATIVE_APP"; reportiumClient.stepEnd(); reportiumClient.stepStart("inject the image"); pars.Clear(); pars.Add("repositoryFile", "PRIVATE:perfectoL.png"); pars.Add("identifier", "Victor.RealTimeFilter"); driver.ExecuteScript("mobile:image.injection:start", pars); reportiumClient.stepEnd(); reportiumClient.stepStart("dismiss popup if it appears"); // rotate the image (device) to show in landscape pars.Clear(); pars.Add("content", "Access the Camera"); pars.Add("timeout", 20); res = (String)driver.ExecuteScript("mobile:checkpoint:text", pars); if (res.ToLower().Equals("true")) { pars.Clear(); pars.Add("label", "OK"); pars.Add("timeout", 10); res = (String)driver.ExecuteScript("mobile:button-text:click", pars); } reportiumClient.stepEnd(); reportiumClient.stepStart("verify the image is displayed"); // rotate the image (device) to show in landscape pars.Clear(); pars.Add("state", "landscape"); driver.ExecuteScript("mobile:device:rotate", pars); pars.Clear(); pars.Add("content", "Perfection"); pars.Add("timeout", 20); res = (String)driver.ExecuteScript("mobile:checkpoint:text", pars); if (res.ToLower().Equals("true")) { reportiumClient.testStop(TestResultFactory.createSuccess()); } else { pars.Clear(); pars.Add("tail", 50); String logStr = (String)driver.ExecuteScript("mobile:device:log", pars); reportiumClient.reportiumAssert("Failed to view image", false); reportiumClient.testStop(TestResultFactory.createFailure("Failed to view image", null)); } } catch (Exception e) { reportiumClient.testStop(TestResultFactory.createFailure(e.Message, e)); } }
public void AppiumTestMethod() { try { reportiumClient.testStart("Calendar assignment", new TestContextTags("assignment3", "calendarApp")); // write your code here reportiumClient.stepStart("Open the Calendar app"); Dictionary <String, Object> pars = new Dictionary <String, Object>(); try { // close the calendar if open to verify that starting from fresh app pars.Add("name", "Calendar"); driver.ExecuteScript("mobile:application:close", pars); } catch (Exception e) { Trace.Write(e.StackTrace); Trace.WriteLine(" "); } pars.Clear(); pars.Add("name", "Calendar"); driver.ExecuteScript("mobile:application:open", pars); reportiumClient.stepEnd(); // Check for What's New Screen and dismiss reportiumClient.stepStart("Dismiss popup"); pars.Clear(); pars.Add("content", "What's New"); pars.Add("timeout", 10); String result = (String)driver.ExecuteScript("mobile:checkpoint:text", pars); if (result.ToLower().Equals("true")) { pars.Clear(); pars.Add("label", "Continue"); pars.Add("threshold", 80); pars.Add("ignorecase", "nocase"); driver.ExecuteScript("mobile:button-text:click", pars); } pars.Clear(); pars.Add("content", "Access"); pars.Add("timeout", 10); result = (String)driver.ExecuteScript("mobile:checkpoint:text", pars); if (result.ToLower().Equals("true")) { pars.Clear(); pars.Add("label", "Don't Allow"); pars.Add("threshold", 80); pars.Add("ignorecase", "nocase"); driver.ExecuteScript("mobile:button-text:click", pars); } reportiumClient.stepEnd(); // Go to add the event screen reportiumClient.stepStart("Open the event add screen"); driver.Context = "NATIVE_APP"; driver.FindElementByName("Add").Click(); // use a checkpoint to visually check that we are on the correct screen pars.Clear(); pars.Add("content", "new event"); pars.Add("timeout", 20); result = (String)driver.ExecuteScript("mobile:checkpoint:text", pars); reportiumClient.stepEnd(); reportiumClient.stepStart("Add location & title"); IWebElement inField = driver.FindElementsByClassName("XCUIElementTypeTextField").ElementAt(1); inField.SendKeys("fun day"); System.Threading.Thread.Sleep(2000); inField = driver.FindElementByName("Location"); inField.SendKeys("London"); driver.FindElementByName("Done").Click(); reportiumClient.stepEnd(); reportiumClient.stepStart("Set start time"); driver.FindElementByName("Starts").Click(); System.Threading.Thread.Sleep(1000); IWebElement hour = driver.FindElementsByClassName("XCUIElementTypePickerWheel").ElementAt(1); String hr = hour.GetAttribute("value"); hour.SendKeys("9"); IWebElement mins = driver.FindElementsByClassName("XCUIElementTypePickerWheel").ElementAt(2); String min = mins.GetAttribute("value"); mins.SendKeys("45"); Trace.WriteLine("old time: " + hr + ':' + min); hr = hour.GetAttribute("value"); min = mins.GetAttribute("value"); Trace.WriteLine("new time: " + hr + ':' + min); reportiumClient.stepEnd(); reportiumClient.stepStart("Set End Time"); driver.FindElementByName("Ends").Click(); System.Threading.Thread.Sleep(2000); hour = driver.FindElementsByClassName("XCUIElementTypePickerWheel").ElementAt(1); hr = hour.GetAttribute("value"); hour.SendKeys("11"); mins = driver.FindElementsByClassName("XCUIElementTypePickerWheel").ElementAt(2); min = mins.GetAttribute("value"); mins.SendKeys("15"); Trace.WriteLine("old end time: " + hr + ':' + min); hr = hour.GetAttribute("value"); min = mins.GetAttribute("value"); Trace.WriteLine("new end time: " + hr + ':' + min); driver.FindElementByName("Ends").Click(); reportiumClient.stepEnd(); reportiumClient.stepStart("Recurring Event"); driver.FindElementByName("Repeat").Click(); driver.FindElementByName("Every Month").Click(); driver.FindElementByName("End Repeat").Click(); driver.FindElementByName("On Date").Click(); System.Threading.Thread.Sleep(3000); IWebElement month = driver.FindElementsByClassName("XCUIElementTypePickerWheel").ElementAt(0); String endMonth = month.GetAttribute("value"); month.SendKeys("December"); IWebElement day = driver.FindElementsByClassName("XCUIElementTypePickerWheel").ElementAt(1); String endDate = day.GetAttribute("value"); day.SendKeys("5"); IWebElement year = driver.FindElementsByClassName("XCUIElementTypePickerWheel").ElementAt(2); String endYear = year.GetAttribute("value"); year.SendKeys("2020"); Trace.WriteLine("old end date: " + endMonth + ' ' + endDate + ", " + endYear); endMonth = month.GetAttribute("value"); endDate = day.GetAttribute("value"); endYear = year.GetAttribute("value"); Trace.WriteLine("new end date: " + endMonth + ' ' + endDate + ", " + endYear); // go back to Event definition screen driver.FindElementByName("New Event").Click(); reportiumClient.stepEnd(); reportiumClient.stepStart("Add Travel time"); driver.FindElementByName("Travel Time").Click(); IWebElement travelToggle = driver.FindElementsByClassName("XCUIElementTypeSwitch").ElementAt(0); travelToggle.Click(); driver.FindElementByName("2 hours").Click(); // go back to Event definition screen driver.FindElementByName("New Event").Click(); reportiumClient.stepEnd(); reportiumClient.stepStart("Close application"); pars.Clear(); pars.Add("name", "Calendar"); driver.ExecuteScript("mobile:application:close", pars); reportiumClient.stepEnd(); reportiumClient.testStop(TestResultFactory.createSuccess()); } catch (Exception e) { reportiumClient.testStop(TestResultFactory.createFailure(e.Message, e)); Trace.Write(e.StackTrace); Trace.WriteLine(" "); } }