appium java簡單實例_Appium創建一個Note的實例

近來通過Appium,Robotium等幾個框架去了解移動平臺自動化測試。Appium官方實例是使用ContactManager.apk,而Robotium使用的是SDK自帶的Notepad.apk,為了方便比較,在了解Appium的同時把實例修改成跟Robotium一致的Notepad.apk并記錄下其中一個Case如下:

1.package majcit.com.AppiumDemo;

2.

3.import io.appium.java_client.AppiumDriver;

4.import io.appium.java_client.TouchAction;

5.

6.import java.io.File;

7.import java.net.URL;

8.import java.util.List;

9.

10.import org.junit.Test;

11.import org.junit.After;

12.import org.junit.Before;

13.import org.openqa.selenium.By;

14.import org.openqa.selenium.WebElement;

15.import org.openqa.selenium.remote.DesiredCapabilities;

16.import static org.hamcrest.Matchers.*;

17.import static org.hamcrest.MatcherAssert.assertThat;

18.

19./**

20. * Unit test for simple App.

21. */

22.public class NoetPadTest {

23. /**

24. * Create the test case

25. *

26. * @param testName name of the test case

27. */

28. private AppiumDriver driver;

29.

30. @Before

31. public void setUp() throws Exception {

32. // set up appium

33. File classpathRoot = new File(System.getProperty("user.dir"));

34. File appDir = new File(classpathRoot, "apps");

35. File app = new File(appDir, "NotePad.apk");

36. DesiredCapabilities capabilities = new DesiredCapabilities();

37. capabilities.setCapability("deviceName","Android");

38. //capabilities.setCapability("platformVersion", "4.2");

39. capabilities.setCapability("platformName", "Android");

40. //capabilities.setCapability("app", app.getAbsolutePath());

41. capabilities.setCapability("appPackage", "com.example.android.notepad");

42. capabilities.setCapability("appActivity", "com.example.android.notepad.NotesList");

43. //capabilities.setCapability("appActivity", ".NotesList");

44. driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

45. }

46.

47. @After

48. public void tearDown() throws Exception {

49. driver.quit();

50. }

51.

52. @Test

53. public void addNoteCNTitle() throws InterruptedException{

54. //Evoke the system menu option

55. driver.sendKeyEvent(82);

56.

57.

58. try {

59. Thread.sleep(1000);

60. }catch(Exception e) {

61. System.out.println(e.getMessage());

62. }

63.

64. //Click on the "Add Note" menu entry

65. WebElement el = driver.findElement(By.name("Add note"));

66. el.click();

67.

68. //Enter the note info and save it

69. WebElement text = driver.findElementByClassName("android.widget.EditText");

70. text.sendKeys("Note 1");

71.

72. driver.sendKeyEvent(82);

73. el = driver.findElement(By.name("Save"));

74. el.click();

75.

76. //Find out the new added note entry

77. List entries = driver.findElements(By.className("android.widget.TextView"));

78.

79. WebElement targetEntry = null;

80. for(WebElement entry : entries) {

81. if(entry.getText().equals("Note1")) {

82. targetEntry = entry;

83. break;

84. }

85. }

86.

87. //Long press on the men entry to call out the context menu options

88. TouchAction action = new TouchAction(driver);

89. action.longPress(targetEntry);

90. //action.moveTo(we,240,10);

91. action.perform();

92.

93. //Find out the menu entry of "Delete"

94. WebElement optionListView = driver.findElement(By.className("android.widget.ListView"));

95. List options = optionListView.findElements(By.className("android.widget.TextView"));

96. WebElement delete = null;

97. for (WebElement option:options) {

98. if (option.getText().equals("Delete")) {

99. delete = option;

100. break;

101.

102. }

103. }

104.

105. assertThat(delete,notNullValue());

106.

107. //Delete the menu entry

108. delete.click();

109.

110. try {

111. Thread.sleep(1000);

112. }catch(Exception e) {

113. System.out.println(e.getMessage());

114. }

115.

116.

117.

118. }

119.

120.}

本文地址:https://blog.csdn.net/qq_31344287/article/details/108732301

如您對本文有疑問或者有任何想說的,請點擊進行留言回復,萬千網友為您解惑!

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/393368.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/393368.shtml
英文地址,請注明出處:http://en.pswp.cn/news/393368.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Lync Server 2013無法共享PPT故障排錯處理

前段時間幫助朋友看了一個關于Lync Server 2013無法共享PPT的問題,共享PPT時報如下錯誤: 日志截圖如下: 原因如下前端服務器未關聯Ofice web Application服務器,關聯即可,如下: 關聯完成后,如下…

leetcode733. 圖像渲染(bfs)

有一幅以二維整數數組表示的圖畫,每一個整數表示該圖畫的像素值大小,數值在 0 到 65535 之間。 給你一個坐標 (sr, sc) 表示圖像渲染開始的像素值(行 ,列)和一個新的顏色值 newColor,讓你重新上色這幅圖像…

chrome擴展程序_如何創建Chrome擴展程序

chrome擴展程序by Erika Tan譚詠麟 如何創建Chrome擴展程序 (How to create a Chrome Extension) In this article, I will be teaching you how to make a Chrome Extension of your own. I’m basing it off of lessons learned while creating TalkToMe, a Chrome Extensio…

對‘初學者應該選擇哪種編程語言’的回答——計算機達人成長之路(38)

7、PASCAL語言(一)一門通,門門通 在計算機學習問題排行版上,有一個問題絕對是穩居榜首,每次提出都能在各大論壇掀起一股頂帖風暴,而各大網站的每個網絡大牛,都會收到無數學院小弟發來弱弱的提問…

leetcode110. 平衡二叉樹(遞歸)

給定一個二叉樹,判斷它是否是高度平衡的二叉樹。本題中,一棵高度平衡二叉樹定義為:一個二叉樹每個節點 的左右兩個子樹的高度差的絕對值不超過1。示例 1:給定二叉樹 [3,9,20,null,null,15,7]3/ \9 20/ \15 7 返回 true 。代碼 /*** Defi…

spring配置文件注解方式引入的兩種方式

一、#{beanID[propertiesName]}方式 <bean id"propertyConfigurer" class"org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"><property name"fileEncoding" value"utf-8" /><property name&…

vsc 搜索特定代碼_特定問題的通用解決方案:何時編寫代碼以及何時編寫代碼...

vsc 搜索特定代碼by Rina Artstain通過麗娜阿斯特斯坦 特定問題的通用解決方案&#xff1a;何時編寫代碼以及何時編寫代碼 (Generic solutions to specific problems: when to write some code and when to just do it) There is a traditional story that tells of a rabbi w…

java手動編譯jar包_Maven 手動添加第三方依賴包及編譯打包和java命令行編譯JAVA文件并使用jar命令打包...

一&#xff0c;實例:新建了一個Maven項目,在eclipse中通過 build path –> configure path….將依賴包添加到工程中后&#xff0c;eclipse不報錯了。但是用Maven命令 mvn clean compile 時出錯如下&#xff1a;原因是在eclipse中添加了 exteneral jar后&#xff0c;還需要在…

SQL like

確定給定的字符串是否與指定的模式匹配。模式可以包含常規字符和通配符字符。模式匹配過程中&#xff0c;常規字符必須與字符串中指定的字符完全匹配。然而&#xff0c;可使用字符串的任意片段匹配通配符。與使用 和 ! 字符串比較運算符相比&#xff0c;使用通配符可使 LIKE 運…

計劃備份mysql數據庫

1:mysql是我們使用最多的數據庫&#xff0c;如果在日常中正確的對mysql數據進行備份&#xff0c;下面我們就來做這事&#xff0c;通過腳本來實現##########################################################################################################################…

leetcode1333. 餐廳過濾器

給你一個餐館信息數組 restaurants&#xff0c;其中 restaurants[i] [idi, ratingi, veganFriendlyi, pricei, distancei]。你必須使用以下三個過濾器來過濾這些餐館信息。 其中素食者友好過濾器 veganFriendly 的值可以為 true 或者 false&#xff0c;如果為 true 就意味著你…

3.27下午

轉載于:https://www.cnblogs.com/bgd140201228/p/6628194.html

2019春季學期進度報告(十四)

課上花費時間&#xff1a;5h 課下花費時間&#xff1a;6h 學會的新內容&#xff1a;阿里云服務器的購買&#xff0c;websockt入門。 代碼量&#xff1a;200h 轉載于:https://www.cnblogs.com/Aduorisk/p/11056750.html

rxjs 怎么使用_使用RxJS Observables進行SUPER SAIYAN

rxjs 怎么使用I loved DragonBall Z as a kid, and still love it as an adult. 我從小就愛DragonBall Z&#xff0c;但從小到大仍然喜歡它。 Among the ludicrous number of transformations, the original Super Saiyan remains my favorite. 在可笑的轉換數量中&#xff0c…

java編程石頭剪刀布_java 開發的石頭,剪刀,布的游戲 demo

[java]代碼庫/** 創建一個類Game&#xff0c;石頭&#xff0c;剪刀&#xff0c;布的游戲。*/public class Game {/*** param args*/String[] s {"石頭","剪刀","布"};//獲取電腦出拳String getComputer(int i){String computerGuess s[i];retur…

JList的基本操作

1.初始化并添加元素 DefaultListModel leftListModelnew DefaultListModel(); String[] items Model.getPairs(); for (int i0; i<items.length; i) { leftListModel.add(i, items[i]); } JList leftLstnew JList(leftListModel); 2.刪除所有元素 leftListModel.remove…

請求WebApi的幾種方式

請求WebApi的幾種方式目前所了解的請求WebAPI的方式有通過后臺訪問api 和通過js 直接訪問api接口 首先介紹下通過后臺訪問api的方法&#xff0c;可以使用HttpClient的方式也可以使用WebRequest的方式 1、HttpClient的方式 &#xff08;1&#xff09;Get請求 string url "…

Django第三篇

前端反向解析 應用場景&#xff1a;通過訪問a路由&#xff0c;到達a的對應視圖函數&#xff0c;函數到達對應的前端a標簽 a標簽的路徑是b路由&#xff0c;如果我們在后端改變b路由的路徑&#xff0c;那么a標簽便無法訪問 到b路由&#xff0c;只能手動在前端改變a標簽的路徑&…

leetcode792. 匹配子序列的單詞數

給定字符串 S 和單詞字典 words, 求 words[i] 中是 S 的子序列的單詞個數。 示例: 輸入: S “abcde” words [“a”, “bb”, “acd”, “ace”] 輸出: 3 解釋: 有三個是 S 的子序列的單詞: “a”, “acd”, “ace”。 class Solution {public int numMatchingSubseq(Strin…

react context_使用React Context API-入門

react contextLets use the React Context API to change theme in an app!讓我們使用React Context API更改應用程序中的主題&#xff01; 但是首先&#xff0c;一些背景 &#xff01; &#xff1f; (But first, some context! ?) Ok terrible puns aside lets have a look …