static void Swipe(Point f, Point t, TimeSpan delay) { var args = new Dictionary <string, object>(); args["command"] = "input swipe"; args["args"] = $"{f.X} {f.Y} {t.X} {t.Y} {delay.TotalMilliseconds}"; args["includeStderr"] = true; args["timeout"] = 10000; _driver.ExecuteScript("mobile: shell", args); }
public static async Task WaitForToastMessage(this AndroidDriver <AndroidElement> driver, String expectedToast) { await Retry.For(async() => { var args = new Dictionary <string, object> { { "text", expectedToast }, { "isRegexp", false } }; driver.ExecuteScript("mobile: isToastVisible", args); }); }
public void TestListInstalledPackages() { AndroidDriver <AppiumWebElement> driver = StartApp(); //get a list of all installed packages on the device string script = "mobile: shell"; var arguments = new Dictionary <string, string> { { "command", "pm list packages" }, { "--show-versioncode", "" } }; var list = driver.ExecuteScript(script, arguments); Assert.IsNotNull(list); Console.Write(list); }
public object ExecuteScript(string script) { return(_driver.ExecuteScript(script)); }
public void AppiumTestMethod() { //Write your test here // Notify Reporting Server that test is starting reportClient.testStart("Wikipedia assignment", new TestContextTags("assignment1", "apple entry")); Dictionary <String, Object> pars = new Dictionary <String, Object>(); try { reportClient.stepStart("Open YouTube"); try { // close the calendar if open to verify that starting from fresh app pars.Add("name", "YouTube"); driver.ExecuteScript("mobile:application:close", pars); } catch (Exception e) { Trace.Write(e.StackTrace); Trace.WriteLine(" "); } pars.Clear(); pars.Add("name", "YouTube"); driver.ExecuteScript("mobile:application:open", pars); driver.Context = "NATIVE_APP"; reportClient.stepEnd(); reportClient.stepStart("Adjust Volume"); MaxVolume(driver); reportClient.stepEnd(); reportClient.stepStart("Activate the audio search"); driver.FindElementByXPath("//*[@content-desc=\"Search\"]").Click(); driver.FindElementByXPath("//*[@resource-id=\"com.google.android.youtube:id/voice_search\"]").Click(); reportClient.stepEnd(); reportClient.stepStart("Play name for audio search"); // Create audio file from String String key = "PRIVATE:mysong.wav"; pars.Clear(); pars.Add("text", "Metallica Master of Puppets"); pars.Add("repositoryFile", key); driver.ExecuteScript("mobile:text:audio", pars); // inject Audio to device pars.Clear(); pars.Add("key", key); pars.Add("wait", "wait"); driver.ExecuteScript("mobile:audio:inject", pars); reportClient.stepEnd(); reportClient.stepStart("Play the music clip and validate"); driver.FindElementByXPath("//*[@content-desc=\"Play album\"]").Click(); pars.Clear(); pars.Add("timeout", 30); pars.Add("duration", 1); String audioR = (String)driver.ExecuteScript("mobile:checkpoint:audio", pars); reportClient.stepEnd(); reportClient.stepStart("Close the app"); // inject Audio to device pars.Clear(); pars.Add("name", "YouTube"); driver.ExecuteScript("mobile:application:close", pars); reportClient.stepEnd(); if (audioR.ToLower().Equals("true")) { reportClient.reportiumAssert("Audio is playing", true); reportClient.testStop(TestResultFactory.createSuccess()); } else { reportClient.reportiumAssert("Audio failed", false); reportClient.testStop(TestResultFactory.createFailure("Audio failed", null)); } } catch (Exception e) { reportClient.testStop(TestResultFactory.createFailure(e.Message, e)); Trace.Write(e.StackTrace); Trace.WriteLine(" "); } }
public void AppiumTestMethod() { //Write your test here try { // write your code here string title = "Test Scripting"; IWebElement field; try { field = driver.FindElementByXPath("//android.widget.TextView[@text='GET STARTED']"); field.Click(); Trace.WriteLine("Pressed the Get Started button to get into the application"); } catch (NoSuchElementException n) { Trace.WriteLine("No Welcome screen - just plow ahead"); } field = driver.FindElementByXPath("//*[@resource-id='com.google.android.keep:id/new_list_button']"); field.Click();; // give the list a title - that can be checked on the main Note-board display field = driver.FindElementByXPath("//*[@resource-id='com.google.android.keep:id/editable_title']"); field.Click(); field.SendKeys(title); // app is now ready to accept text for the first list item field = driver.FindElementByXPath("//android.widget.EditText[@resource-id='com.google.android.keep:id/description' and @text ='']"); field.Click(); field.SendKeys("Select app to test"); // click the add field field = driver.FindElementByXPath("//android.widget.ImageView[parent::android.widget.LinearLayout[@content-desc='Add list item']]"); field.Click(); // Enter the second line in the list field = driver.FindElementByXPath("//android.widget.EditText[@resource-id='com.google.android.keep:id/description' and @text ='']"); field.SendKeys("Write the script"); // click the add field field = driver.FindElementByXPath("//android.widget.ImageView[parent::android.widget.LinearLayout[@content-desc='Add list item']]"); field.Click(); // return to the Note-board field = driver.FindElementByClassName("android.widget.ImageButton"); field.Click(); try { //Verify that new note appears on the Note-board field = driver.FindElementByXPath("//android.widget.TextView[@resource-id='com.google.android.keep:id/title' and @text='" + title + "']"); } catch (NoSuchElementException f) { Trace.WriteLine("Did not find the note on the NoteBoard"); } // cleanup the application before closing the connection String cmnd = "mobile:application:clean"; Dictionary <String, Object> pars = new Dictionary <String, Object>(); pars.Add("name", "keep"); driver.ExecuteScript(cmnd, pars); } catch (Exception e) { Trace.WriteLine("Script failed with the exception:" + e.Message); } }
public void AppiumTestMethod() { //Write your test here try { // write your code here By newList = By.XPath("//*[@resource-id='com.google.android.keep:id/new_list_button']"); By titleF = By.XPath("//*[@resource-id='com.google.android.keep:id/editable_title']"); By newItem = By.XPath("//*[@resource-id='com.google.android.keep:id/add_item_text_view']"); By addItem = By.XPath("//*[@resource-id='com.google.android.keep:id/add_item_extra_text_view']"); By descLine = By.XPath("//*[@resource-id='com.google.android.keep:id/description' and @focusable='true']"); IWebElement field; //first point of interest WindTunnelUtils.PointOfInterest(driver, "Adding the list", PointOfInterestStatus.Success); String title = "Test Scripting"; field = driver.FindElement(newList); field.Click();; // give the list a title - that can be checked on the main Note-board display field = driver.FindElement(titleF); field.SendKeys(title); // app is now ready to accept text for the first list item field = driver.FindElement(newItem); field.Click(); field.SendKeys("Select app to test"); // click the add field field = driver.FindElement(addItem); field.Click(); // Enter the second line in the list field = driver.FindElement(newItem); field.SendKeys("Write the script"); // click the add field field = driver.FindElement(addItem); field.Click(); // return to the Note-board field = driver.FindElementByClassName("android.widget.ImageButton"); field.Click(); // Second POI - completed the list. WindTunnelUtils.PointOfInterest(driver, "Completed entry", PointOfInterestStatus.Success); try { //Verify that new note appears on the Note-board field = driver.FindElementByXPath("//*[@resource-id=\"com.google.android.keep:id/title\" and @text=\"" + title + "\"]"); WindTunnelUtils.PointOfInterest(driver, "Found list on NoteBoard", PointOfInterestStatus.Success); } catch (NoSuchElementException f) { Trace.WriteLine("Did not find the note on the NoteBoard"); WindTunnelUtils.PointOfInterest(driver, "Failed to find list on NoteBoard", PointOfInterestStatus.Failure); } // cleanup the application before closing the connection String cmnd = "mobile:application:clean"; Dictionary <String, Object> pars = new Dictionary <String, Object>(); pars.Add("name", "keep"); driver.ExecuteScript(cmnd, pars); } catch (Exception e) { Trace.WriteLine("Script failed with the exception:" + e.Message); } }
private static string ExecuteShellAdbCommand(AndroidDriver <AndroidElement> androidDriver, string command, params string[] args) { return(androidDriver.ExecuteScript("mobile: shell", new AdbCommand(command, args).ToString()).ToString()); }
public void PerformRandomShellCommandAsJson() { string result = _driver.ExecuteScript("mobile: shell", "{\"command\": \"dumpsys\", \"args\": [\"battery\", \"reset\"]}").ToString(); Debug.WriteLine(result); }
static void Main(string[] args) { // AppiumOptions opt = new AppiumOptions(); // opt.AddAdditionalCapability("deviceName", "emulator-5554"); // opt.AddAdditionalCapability("platformName", "Android"); // // opt.AddAdditionalCapability("browserName", "chrome"); // opt.AddAdditionalCapability("udid", "emulator-5554"); // opt.AddAdditionalCapability("app", @"E:\DHLe-MobileV0.1.6.apk"); //// opt.AddAdditionalCapability("automationName", "UIAutomator2"); // AndroidDriver<IWebElement> driver = // new AndroidDriver<IWebElement>(new Uri("http://*****:*****@"E:\DHLe-MobileV0.1.6.apk"); opt.AddAdditionalCapability("automationName", "UIAutomator2"); opt.AddAdditionalCapability("appPackage", "org.khanacademy.android"); opt.AddAdditionalCapability("appActivity", "org.khanacademy.android.ui.library.MainActivity"); opt.AddAdditionalCapability("noReset", true); driver = new AndroidDriver <IWebElement>(new Uri("http://localhost:4723/wd/hub"), opt); driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(30); if (driver.FindElementsByAndroidUIAutomator("UiSelector().text(\"Dismiss\")").Count > 0) { driver.FindElementByAndroidUIAutomator("UiSelector().text(\"Dismiss\")").Click(); } driver.FindElementById("org.khanacademy.android:id/tab_bar_button_profile").Click(); driver.FindElementByAndroidUIAutomator("UiSelector().textContains(\"Sign up\")").Click(); driver.FindElementByAndroidUIAutomator("UiSelector().textContains(\"Birth\")").Click(); ReadOnlyCollection <IWebElement> dateEle = driver.FindElementsById("android:id/numberpicker_input"); //foreach(IWebElement ele in dateEle) //{ // Console.WriteLine(ele.Text); //} dateEle[0].Click(); dateEle[0].Clear(); dateEle[0].SendKeys("Aug"); driver.FindElementByAndroidUIAutomator("UiSelector().textContains(\"OK\")").Click(); driver.FindElementByAndroidUIAutomator("UiSelector().text(\"Home\")").Click(); Size size = driver.Manage().Window.Size; int width = size.Width; int height = size.Height; while (driver.FindElementsByAndroidUIAutomator("UiSelector().textContains(\"College\")").Count == 0) { //scroll TouchAction action = new TouchAction(driver); //action.Tap(100, 500, 6).Perform(); //action.Press(width / 2, 3 * height / 4).MoveTo(width / 2, height / 4).Release().Perform(); Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("command", "input touchscreen swipe 250 800 250 400"); driver.ExecuteScript("mobile:shell", dic); } driver.FindElementByAndroidUIAutomator("UiSelector().textContains(\"College\")").Click(); //IWebDriver d = new ChromeDriver(); //ITakesScreenshot ts = (ITakesScreenshot)d; //ts.GetScreenshot().SaveAsFile("Error.png"); ; } catch (Exception e) { Console.WriteLine(e.Message); // string path = Directory.GetParent(Directory.GetCurrentDirectory()).Name; driver.GetScreenshot().SaveAsFile("Error.png"); } }