日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

appium java简单实例_Appium创建一个Note的实例

發布時間:2023/12/9 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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

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

總結

以上是生活随笔為你收集整理的appium java简单实例_Appium创建一个Note的实例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。