/** * 编辑病例 * * @param age * @return */ public static String editCase(String age) { WebElement eEditBtn = driver.findElement(By.id(edit_case_btn)); eEditBtn.click(); WebElement eAgeYear = driver.findElement(By.id(age_year_input)); eAgeYear.clear(); eAgeYear.sendKeys(age); boolean flag = Utils.swipe(driver, By.id(pub_case), 2); if (flag) { WebElement eEditCase = driver.findElement(By.id(pub_case)); eEditCase.click(); } else { Assertion.assertEquals(true, flag, "发布按钮未找到,请检查后再试!"); } String terminalAge = ""; boolean findCaseAge = Utils.isElementExist(driver, By.id(terminal_age)); int num = 0; if (findCaseAge == false) { while (findCaseAge == false && num < 10) { findCaseAge = Utils.isElementExist(driver, By.id(terminal_age)); System.out.println(num); if (findCaseAge) { terminalAge = Utils.getText(driver, By.id(terminal_age)); } else { num++; } } } else { terminalAge = Utils.getText(driver, By.id(terminal_age)); } return terminalAge; }
@After public void tearDown() throws Exception { common.takeScreenShotOnFailed(name.getMethodName()); if (fileHasBeenCreated) { FileListView fileListView = new FileListView(driver); Actions.deleteElement(CurrentCreatedFile, fileListView, driver); } driver.removeApp("com.owncloud.android"); driver.quit(); }
/** * Sets the network connection Status. Android only.<br> * Possible values:<br> * Value |(Alias) | Data | Wifi | Airplane Mode<br> * -------------------------------------------------<br> * 0 |(None) | 0 | 0 | 0<br> * 1 |(Airplane Mode) | 0 | 0 | 1<br> * 2 |(Wifi only) | 0 | 1 | 0<br> * 4 |(Data only) | 1 | 0 | 0<br> * 6 |(All network on) | 1 | 1 | 0<br> * * @param connectionStatus The network status value */ @RobotKeyword @ArgumentNames({"connectionStatus"}) public void setNetworkConnectionStatus(String connectionStatus) { AppiumDriver driver = applicationManage.getCurrentDriver(); int status = Integer.parseInt(connectionStatus); if (driver instanceof AndroidDriver) { AndroidDriver android = (AndroidDriver) driver; NetworkConnectionSetting setting = new NetworkConnectionSetting(status); android.setNetworkConnection(setting); } else { throw new AppiumLibraryFatalException("This keyword only support android platform"); } }
/** * Returns an integer bitmask specifying the network connection type. Android only.<br> * See `set network connection status` for more details. * * @return The andorid network current status */ @RobotKeyword public String getNetworkConnectionStatus() { String status = null; AppiumDriver driver = applicationManage.getCurrentDriver(); if (driver instanceof AndroidDriver) { AndroidDriver android = (AndroidDriver) driver; status = android.getNetworkConnection().value + ""; } else { throw new AppiumLibraryFatalException("This keyword only support android platform"); } return status; }
// ######## Check Login functionality/ throws InterruptedException########################### @Test public void A_login() { // navigation();sreens();more();sharing(); throws InterruptedException driver.findElement(By.xpath("//android.widget.Button[@text='MiMedia Login']")).click(); // driver.findElement(By.name("Email address")).sendKeys("*****@*****.**"); // .sendKeyEvent(47);driver.sendKeyEvent(29);driver.sendKeyEvent(49);driver.sendKeyEvent(46);driver.sendKeyEvent(29);driver.sendKeyEvent(50);driver.sendKeyEvent(7);driver.sendKeyEvent(11);driver.sendKeyEvent(39);driver.sendKeyEvent(49);driver.sendKeyEvent(41);driver.sendKeyEvent(29);driver.sendKeyEvent(46);driver.sendKeyEvent(77);driver.sendKeyEvent(35);driver.sendKeyEvent(41);driver.sendKeyEvent(29);driver.sendKeyEvent(37);driver.sendKeyEvent(40);driver.sendKeyEvent(56);driver.sendKeyEvent(31);driver.sendKeyEvent(43);driver.sendKeyEvent(41); // driver.findElement(By.id("com.mimedia.gallery:id/login_password")).click(); // driver.sendKeyEvent(41);driver.sendKeyEvent(29);driver.sendKeyEvent(42);driver.sendKeyEvent(38);driver.sendKeyEvent(49);driver.sendKeyEvent(38);driver.sendKeyEvent(36);driver.sendKeyEvent(29);driver.sendKeyEvent(77);driver.sendKeyEvent(8); driver.findElement(By.name("LOG IN")).click(); driver.findElement(By.name("COOL!")).click(); driver.findElement(By.name("OK!")).click(); }
@Test public void addContact() { WebElement el = driver.findElement(By.name("Add Contact")); el.click(); // List<AndroidElement> textFieldsList = // driver.findElementsByClassName("android.widget.EditText"); List<WebElement> textFieldsList = driver.findElementsByClassName("android.widget.EditText"); textFieldsList.get(0).sendKeys("Some Name"); textFieldsList.get(2).sendKeys("*****@*****.**"); driver.swipe(100, 500, 100, 100, 2); driver.findElementByName("Save").click(); }
@Test(groups = {"taobao"}) public void webDriver() { driver.get("http://m.taobao.com/"); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS); MobileElement tmall = (MobileElement) driver.findElementByXPath("//div[@id='a6636-1']"); tmall.swipe(SwipeElementDirection.DOWN, 1000); tmall.tap(1, 1000); HashMap<String, Integer> tapObject = new HashMap<String, Integer>(); tapObject.put("x", 120); tapObject.put("y", 120); tapObject.put("touchCount", 1); tapObject.put("duration", 1200); driver.executeScript("mobile: tap", tapObject); JavascriptExecutor js = (JavascriptExecutor) driver; HashMap<String, Double> flickObject = new HashMap<String, Double>(); flickObject.put("startX", 200.0); flickObject.put("startY", 700.5); flickObject.put("endX", 200.2); flickObject.put("endY", 100.5); js.executeScript("mobile: flick", flickObject); TouchAction action = new TouchAction(driver); action.press(tmall).waitAction(400).perform(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS); List<WebElement> elements = driver.findElementsByXPath("//ul/li/a[@class='card-item card-style-chn']"); for (WebElement e : elements) { System.out.println(e.getAttribute("href")); } driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); System.out.println(driver.getPageSource()); }
// ####UI & Layout/Check all sreens/Camera/Upload status indicator/Test case NO: #### @Test public void C_sreens() { driver.findElement(By.name("Collections")).click(); driver.findElement(By.name("COOL!")).click(); driver.findElement(By.name("MiDrive")).click(); driver.findElement(By.name("COOL!")).click(); driver.findElement(By.name("Collections")).click(); // driver.findElement(By.name("Gallery")).click(); // driver.findElement(By.xpath("//*[@class='android.widget.TextView' and @index='1']")).click(); // List<WebElement> editBox=driver.findElements(By.className("android.widget.TextView")); // editBox.get(4).click(); }
/** * 到个人中心——发布的病例查看刚发布的病例 * * @return */ public static WebElement checkCase() { WebElement eMainMenu = driver.findElement(By.className(IndexPageElements.MAIN_MENU)); eMainMenu.click(); WebElement ePersonalCerter = driver.findElement(By.id(MainMenuPageElements.PERSONAL_CERTER)); ePersonalCerter.click(); WebElement eReleaseCase = driver.findElement(By.id(PerCenterPageElements.RELEASE_CASE)); eReleaseCase.click(); WebElement eReleaseCaseTitle = driver.findElement(By.id(PerCenterPageElements.RELEASE_CASE_TITLE)); return eReleaseCaseTitle; }
/** * Puts the data in the file specified as `path`. Android only.<br> * * @param path the path on the device * @param data data to be written to the file * @param encode true/false encode the data as base64 before writing it to the file * (default=false) */ @RobotKeyword @ArgumentNames({"path", "data", "encode=false"}) public void pushFile(String path, String data, String encode) { AppiumDriver driver = applicationManage.getCurrentDriver(); boolean isEncode = Boolean.parseBoolean(encode); if (driver instanceof AndroidDriver) { AndroidDriver android = (AndroidDriver) driver; if (isEncode) { data = Base64.encodeBase64String(data.getBytes()); } android.pushFile(path, data.getBytes()); } else { throw new AppiumLibraryFatalException("This keyword only support android platform"); } }
@BeforeMethod public void setUp() throws MalformedURLException { File app = new File(sAPKFile); capabilities = new DesiredCapabilities(); capabilities.setCapability( "automationName", genericLib.getCongigValue(sConfigFile, "AUTOMATIONNAME")); capabilities.setCapability( "platformName", genericLib.getCongigValue(sConfigFile, "PLATFORMNAME")); capabilities.setCapability( "platformVersion", genericLib.getCongigValue(sConfigFile, "PLATFORMVERSION")); // "4.4"); capabilities.setCapability( "deviceName", genericLib.getCongigValue(sConfigFile, "DEVICENAME")); // "ASUS_T00J"); capabilities.setCapability("app", app.getAbsolutePath()); capabilities.setCapability( "apppackage", genericLib.getCongigValue( sConfigFile, "APPPACKAGE")); // "com.disha.quickride"); // This is package name of your app (you can // get it from apk info app) capabilities.setCapability( "appactivity", genericLib.getCongigValue( sConfigFile, "APPACTIVITY")); // "com.disha.quickride.androidapp.startup.SplashActivity"); // This is // Launcher activity of your app (you can get it from apk info app) driver = new AndroidDriver(new URL(genericLib.getCongigValue(sConfigFile, "URL")), capabilities); driver.manage().timeouts().implicitlyWait(60000, TimeUnit.SECONDS); }
@Test public void G_sharing() { // driver.findElement(By.name("Gallery")).click(); // List<WebElement> editBox=driver.findElements(By.className("android.widget.TextView")); // editBox.get(3).click(); List<WebElement> collection1 = driver.findElements(By.className("android.view.View")); // Taping on Collection folder collection1.get(5).click(); driver.findElement(By.xpath("//*[@class='android.view.View' and @index='2']")).click(); // TouchAction tActionn=new TouchAction(driver); //Tap function // tActionn.tap(150,301).release().perform(); driver.findElementByAccessibilityId("Share").click(); driver.navigate().back(); driver.findElement(By.id("com.mimedia.gallery:id/gallery_action_bar_nav_icon")).click(); }
public void acceptAlert() { Log.logInfo("accept alerts"); if (waitForText(20, "记住我的选择", "禁止", "允许")) { Log.logInfo("点击[允许]"); driver.findElement(By.name("允许")).click(); } }
/** * Retrieves the file at `path` and return it's content. Android only.<br> * * @param path the path to the file on the device * @param decode true/false decode the data (base64) before returning it (default=false) * @return The pull file content */ @RobotKeyword @ArgumentNames({"path", "decode=false"}) public String pullFile(String path, String decode) { AppiumDriver driver = applicationManage.getCurrentDriver(); boolean isDecode = Boolean.parseBoolean(decode); byte[] theFile = null; if (driver instanceof AndroidDriver) { AndroidDriver android = (AndroidDriver) driver; theFile = android.pullFile(path); if (isDecode) { theFile = Base64.decodeBase64(theFile); } } else { throw new AppiumLibraryFatalException("This keyword only support android platform"); } return new String(theFile); }
@BeforeClass @Parameters({"LOGIN_PHONE_USER", "GLOBAL_PASSWORD"}) public void setUp(String username, String password) { driver = DriverList.androidDriverRun(); driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS); new SearchPageElements(driver); new LoginPageElements(driver); LoginPageElements.allinLogin(username, password); }
public void goToSettings() { // if (System.getProperty("platform").startsWith("android")){ // ((AndroidDriver) driver).sendKeyEvent(AndroidKeyCode.MENU); // settingsPage.clickOnSettings(); // } if (driver instanceof AndroidDriver) { ((AndroidDriver) driver).sendKeyEvent(AndroidKeyCode.MENU); settingsPage.clickOnSettings(); } }
@Test public void launchingWatsapp() throws IOException, InterruptedException { stopAppiumServer(); startAppiumServer(); capabilities = new DesiredCapabilities(); capabilities.setCapability("automationName", "Appium"); capabilities.setCapability("platformName", "Android"); capabilities.setCapability("platformVersion", "4.4.4"); capabilities.setCapability("deviceName", "Samsung Galaxy S5 - 4.4.4 - API 19 - 1080x1920"); capabilities.setCapability("app", appPath); capabilities.setCapability("appPackage", "com.whatsapp"); capabilities.setCapability("appActivity", "com.whatsapp.Main"); System.out.println("Trying to start the driver"); driver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); Thread.sleep(5000); if (driver.findElement(By.id("com.whatsapp:id/parentPanel")).isDisplayed()) { driver.findElement(By.id("android:id/button2")).click(); System.out.println("Successfully clicked on the \"OK\" button"); } // driver.findElement(By.partialLinkText("Agree and continue")).click(); driver .findElementByAndroidUIAutomator("new UiSelector().textMatches(\"Agree and continue\")") .click(); if (!(driver .findElement(By.id("com.whatsapp:id/registration_country")) .getText() .equalsIgnoreCase("United States"))) { driver.findElement(By.id("com.whatsapp:id/registration_country")).sendKeys("United States"); } driver.findElement(By.id("com.whatsapp:id/registration_phone")).sendKeys("1234567890"); driver.findElement(By.id("com.whatsapp:id/registration_submit")).click(); Thread.sleep(30000); try { if (driver.findElement(By.id("android.widget.LinearLayout")).isDisplayed()) { driver.findElement(By.id("android:id/button1")).click(); } } catch (Exception e) { } }
/** 验证搜索结果列表话题tag页 */ @Test(priority = 4) public void assertTopic() { WebElement eTopicBtn = driver.findElement(By.id(SearchPageElements.search_topic)); eTopicBtn.click(); List<String> topicInfo = SearchPageElements.getResourceName(); System.out.println("\n话题tab页搜索结果:"); for (int i = 0; i < topicInfo.size() - 1; i++) { System.out.println(topicInfo.get(i)); // Assertion.assertEquals(true, topicInfo.get(i).contains(keyword), "搜索结果显示错误,请检查!"); } }
/** 验证搜索结果列表视频tag页 */ @Test(priority = 3) public void assertVideo() { WebElement eVideoBtn = driver.findElement(By.id(SearchPageElements.search_video)); eVideoBtn.click(); List<String> videoInfo = SearchPageElements.getResourceName(); System.out.println("\n视频tab页搜索结果:"); for (int i = 0; i < videoInfo.size() - 1; i++) { System.out.println(videoInfo.get(i)); // Assertion.assertEquals(true, videoInfo.get(i).contains(keyword), "搜索结果显示错误,请检查!"); } }
/** 验证搜索结果列表病例tag页 */ @Test(priority = 2) public void assertCase() { WebElement eCaseBtn = driver.findElement(By.id(SearchPageElements.search_case)); eCaseBtn.click(); List<String> caseInfo = SearchPageElements.getResourceName(); System.out.println("\n病例tab页搜索结果:"); for (int i = 0; i < caseInfo.size() - 1; i++) { System.out.println(caseInfo.get(i)); // Assertion.assertEquals(true, caseInfo.get(i).contains(keyword), "搜索结果显示错误,请检查!"); } }
/** 验证搜索结果列表医师tag页 */ @Test(priority = 6) public void assertLabel() { WebElement eLabelBtn = driver.findElement(By.id(SearchPageElements.search_label)); eLabelBtn.click(); List<String> labelName = SearchPageElements.getLabelName(); System.out.println("\n标签tab页搜索结果:"); for (int i = 0; i < labelName.size() - 1; i++) { System.out.println(labelName.get(i)); Assertion.assertEquals(true, labelName.get(i).contains(keyword), "搜索结果显示错误,请检查!"); } }
/** 验证搜索结果列表医师tag页 */ @Test(priority = 5) public void assertDoctor() { WebElement eDoctorBtn = driver.findElement(By.id(SearchPageElements.search_user)); eDoctorBtn.click(); List<String> doctorName = SearchPageElements.getDoctorName(); System.out.println("\n医师tab页搜索结果:"); for (int i = 0; i < doctorName.size() - 1; i++) { System.out.println(doctorName.get(i)); // Assertion.assertEquals(true, doctorName.get(i).contains(keyword), "搜索结果显示错误,请检查!"); } }
@Test public void H_swipe() { driver.findElement(By.xpath("//*[@class='android.view.View' and @index='0']")).click(); JavascriptExecutor js = (JavascriptExecutor) driver; HashMap<String, Double> swipeObject = new HashMap<String, Double>(); swipeObject.put("startX", 2.00); swipeObject.put("startY", 272.00); swipeObject.put("endX", 670.00); swipeObject.put("endY", 272.00); swipeObject.put("duration", 2.0); js.executeScript("mobile: swipe", swipeObject); }
// MT05 @RelatedIssue(issueID = "HG-730") @Test( groups = {"MercuryLightboxTest_005", "MercuryLightboxTests", "Mercury"}, enabled = false) public void MercuryLightboxTest_005_BackButtonCloseLightbox() { AndroidDriver mobileDriver = NewDriverProvider.getMobileDriver(); LightboxComponentObject lightbox = new LightboxComponentObject(driver); lightbox.openMercuryArticleByName(wikiURL, MercurySubpages.GALLERY); String oldUrl = driver.getCurrentUrl(); lightbox.clickGalleryImage(0); Assertion.assertTrue(lightbox.isLightboxOpened(), "Lightbox is closed"); mobileDriver.execute(DriverCommand.GO_BACK, null); boolean result = !lightbox.isLightboxOpened(); PageObjectLogging.log("Lightbox", "is closed", "is opened", result); result = oldUrl.equals(driver.getCurrentUrl()); PageObjectLogging.log("URL", "is the same", "is different", result); }
/** * 删除病例 * * @return */ public static boolean deleteCase() { WebElement eEditBtn = driver.findElement(By.id(edit_case_btn)); eEditBtn.click(); Utils.sleep(5); boolean flag = Utils.swipe(driver, By.id(delete_case_btn), 5); if (flag) { WebElement eDeleteCase = driver.findElement(By.id(delete_case_btn)); eDeleteCase.click(); } else { Assertion.assertEquals(true, flag, "删除按钮未找到,请检查后再试!"); } boolean deleteCaseContent = Utils.isElementExist(driver, By.id(delete_case_message)); int num = 0; while (deleteCaseContent == false && num < 10) { System.out.println(num); deleteCaseContent = Utils.isElementExist(driver, By.id(delete_case_message)); num++; } return deleteCaseContent; }
/** 返回至首页。 */ @Override public void backToHomePage(String[] contents) { int times = 0; while (!waitForText(5, contents)) { if (times >= 30) { Log.logInfo("尝试多次未能返回到首页,终止操作!"); break; } Log.logInfo("点击返回按钮"); driver.pressKeyCode(AndroidKeyCode.BACK); sendKeyEvent(AndroidKeyCode.BACK, "点击返回按钮"); times++; } }
@Test public void E_collectionscreen() { driver.findElement(By.name("Collections")).click(); WebElement plus = driver.findElement(By.id("com.mimedia.gallery:id/merged_collection_list_create")); plus.click(); driver.findElement(By.name("New collection")).sendKeys("Simone"); driver.findElement(By.name("Create")).click(); driver.findElement(By.id("com.mimedia.gallery:id/gallery_action_bar_nav_icon")).click(); List<WebElement> editBox = driver.findElements(By.className("android.view.View")); // select collections folder editBox.get(6).click(); driver.findElement(By.id("com.mimedia.gallery:id/gallery_action_bar_nav_icon")).click(); }
// WebDriver driver; @BeforeSuite public void testApp() throws MalformedURLException, InterruptedException { // set up appium File app = new File("F:\\EXE Files\\Mobile Testing\\Apk\\MiGallery_1.0.17.715_production.apk"); DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(CapabilityType.BROWSER_NAME, ""); capabilities.setCapability("platformName", "Android"); capabilities.setCapability("deviceName", "A05510"); capabilities.setCapability("platformVersion", "5.0.2"); capabilities.setCapability("app", app.getAbsolutePath()); capabilities.setCapability("appPackage", "com.mimedia.gallery"); capabilities.setCapability("appActivity", "com.mimedia.gallery.GalleryStartupActivity_"); driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS); }
@BeforeSuite public void setUpAppium() throws MalformedURLException, InterruptedException { server = AppiumDriverLocalService.buildService( new AppiumServiceBuilder() .usingDriverExecutable(new File("C://Program Files//nodejs//node.exe")) .withAppiumJS( new File("C://Program Files//Appium//node_modules//appium//bin//appium.js")) .withIPAddress("127.0.0.1") .usingAnyFreePort()); server.start(); Thread.sleep(2000); File appDir = new File("C:\\Users\\FC\\workspace\\fropcorn\\src\\test\\java"); File app = new File(appDir, "fropcorndev.apk"); DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android"); // capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME,"Appium"); capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "5.1.1"); capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "a01b27a8"); capabilities.setCapability(MobileCapabilityType.APP_PACKAGE, "com.fropcorn.www"); // capabilities.setCapability(MobileCapabilityType.APP_WAIT_PACKAGE, "com.fropcorn.www"); capabilities.setCapability( MobileCapabilityType.APP_ACTIVITY, "md569a6b40b6c9dd89241ed1fe199a0a771.SplashScreen"); // capabilities.setCapability(MobileCapabilityType.APP_WAIT_ACTIVITY, // "md512edb7b4c20f0852a0829c1270f9f40a.RegistrationActivity"); // capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath()); driver = new AndroidDriver<MobileElement>(server, capabilities); driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS); // final String URL_STRING = "http://127.0.0.1:4723/wd/hub"; // // URL url = new URL(URL_STRING); // // //Use a empty DesiredCapabilities object // driver = new AndroidDriver<MobileElement>(url, new DesiredCapabilities()); // // //Use a higher value if your mobile elements take time to show up // driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS); }
@Test public void D_camera() { // driver.findElement(By.name("Gallery")).click(); driver.findElementByAccessibilityId("Camera").click(); WebDriver augmentedDriver = new Augmenter().augment(driver); // Landscape orientation ((Rotatable) augmentedDriver).rotate(ScreenOrientation.LANDSCAPE); // Landscape orientation driver.findElement(By.id("com.android.camera2:id/second_shutter_button")).click(); driver.findElement(By.id("com.android.camera2:id/third_shutter_button")).click(); driver.findElement(By.id("com.android.camera2:id/third_shutter_button")).click(); WebDriver augmentedDriver1 = new Augmenter().augment(driver); // Landscape orientation ((Rotatable) augmentedDriver1).rotate(ScreenOrientation.PORTRAIT); { driver.findElement(By.id("com.android.camera2:id/second_shutter_button")).click(); } driver.findElement(By.id("com.android.camera2:id/third_shutter_button")).click(); driver.findElement(By.id("com.android.camera2:id/third_shutter_button")).click(); driver.navigate().back(); }