重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
这篇文章给大家介绍Appium中怎么创建一个Note,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。
公司主营业务:成都网站设计、成都做网站、移动网站开发等业务。帮助企业客户真正实现互联网宣传,提高企业的竞争能力。创新互联公司是一支青春激扬、勤奋敬业、活力青春激扬、勤奋敬业、活力澎湃、和谐高效的团队。公司秉承以“开放、自由、严谨、自律”为核心的企业文化,感谢他们对我们的高要求,感谢他们从不同领域给我们带来的挑战,让我们激情的团队有机会用头脑与智慧不断的给客户带来惊喜。创新互联公司推出砀山免费做网站回馈大家。
近来通过Appium,Robotium等几个框架去了解移动平台自动化测试。Appium官方实例是使用ContactManager.apk,而Robotium使用的是SDK自带的Notepad.apk,为了方便比较,在了解Appium的同时把实例修改成跟Robotium一致的Notepad.apk并记录下其中一个Case如下:
package majcit.com.AppiumDemo; import io.appium.java_client.AppiumDriver; import io.appium.java_client.TouchAction; import java.io.File; import java.net.URL; import java.util.List; import org.junit.Test; import org.junit.After; import org.junit.Before; import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.DesiredCapabilities; import static org.hamcrest.Matchers.*; import static org.hamcrest.MatcherAssert.assertThat; /** * Unit test for simple App. */ public class NoetPadTest { /** * Create the test case * * @param testName name of the test case */ private AppiumDriver driver; @Before public void setUp() throws Exception { // set up appium File classpathRoot = new File(System.getProperty("user.dir")); File appDir = new File(classpathRoot, "apps"); File app = new File(appDir, "NotePad.apk"); DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("deviceName","Android"); //capabilities.setCapability("platformVersion", "4.2"); capabilities.setCapability("platformName", "Android"); //capabilities.setCapability("app", app.getAbsolutePath()); capabilities.setCapability("appPackage", "com.example.android.notepad"); capabilities.setCapability("appActivity", "com.example.android.notepad.NotesList"); //capabilities.setCapability("appActivity", ".NotesList"); driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); } @After public void tearDown() throws Exception { driver.quit(); } @Test public void addNoteCNTitle() throws InterruptedException{ //Evoke the system menu option driver.sendKeyEvent(82); try { Thread.sleep(1000); }catch(Exception e) { System.out.println(e.getMessage()); } //Click on the "Add Note" menu entry WebElement el = driver.findElement(By.name("Add note")); el.click(); //Enter the note info and save it WebElement text = driver.findElementByClassName("android.widget.EditText"); text.sendKeys("Note 1"); driver.sendKeyEvent(82); el = driver.findElement(By.name("Save")); el.click(); //Find out the new added note entry Listentries = driver.findElements(By.className("android.widget.TextView")); WebElement targetEntry = null; for(WebElement entry : entries) { if(entry.getText().equals("Note1")) { targetEntry = entry; break; } } //Long press on the men entry to call out the context menu options TouchAction action = new TouchAction(driver); action.longPress(targetEntry); //action.moveTo(we,240,10); action.perform(); //Find out the menu entry of "Delete" WebElement optionListView = driver.findElement(By.className("android.widget.ListView")); List options = optionListView.findElements(By.className("android.widget.TextView")); WebElement delete = null; for (WebElement option:options) { if (option.getText().equals("Delete")) { delete = option; break; } } assertThat(delete,notNullValue()); //Delete the menu entry delete.click(); try { Thread.sleep(1000); }catch(Exception e) { System.out.println(e.getMessage()); } } }
关于Appium中怎么创建一个Note就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。