qileilove

          blog已經轉移至github,大家請訪問 http://qaseven.github.io/

          基于APPIUM的移動自動化測試

           Appium一款開源自動化測試工具,可以非常快捷的為iOS和Android移動平臺創建功能自動化測試用例。相比其他的移動自動化測試工具,Appium測試由于調用了Selenium的client庫使其可以使用任意的語言,包括PythonRuby、Node.js,Objective,java等。

            本文我們主要討論如何通過junit java example tests測試完成iOS sample apps的測試(此處我們還會創建TestNG example Tests)

            當然在開始之前,我們首先需要下載Appium,下載地址為https://github.com/appium/appium,根據安裝說明我們可以完成Appium的安裝。

            運行以下命令行構建sample projects:

          grunt buildApp:TestApp
          grunt buildApp:UICatalog

            一旦sample projects完成構建,即可通過以下命令啟動Appium:

          grunt appium

            變更工作目錄到sample-code/examples/java/junit,運行測試

          mvn test

            或運行單個測試:

          mvn -Dtest=com.saucelabs.appium.SimpleTest test

            Java Appium測試與Selenium Test非常的相似,你可以創建一個RemoteWebDriver實例并指定DesiredCapabilities,腳本如下:

          @Before
          public void setUp() throws Exception {
              // set up appium against a local application
              File appDir = new File(System.getProperty("user.dir"), "../../../apps/TestApp/build/Release-iphonesimulator");
           
              File app = new File(appDir, "TestApp.app");
              DesiredCapabilities capabilities = new DesiredCapabilities();
              capabilities.setCapability(CapabilityType.BROWSER_NAME, "iOS");
              capabilities.setCapability(CapabilityType.VERSION, "6.0");
              capabilities.setCapability(CapabilityType.PLATFORM, "Mac");
           
              //tell Appium where the location of the app is
              capabilities.setCapability("app", app.getAbsolutePath());
           
              //create a RemoteWebDriver, the default port for Appium is 4723
              driver = new RemoteWebDriver(new URL(http://127.0.0.1:4723/wd/hub), capabilities);
          }

            完成以上腳本后即可直接通過類似selenium測試的方式完成測試腳本:

          @Test
          public void example() throws Exception {
           
              // find an element by tag name
              WebElement button = driver.findElement(By.tagName("button"));
              button.click();
           
              // get the value of the element
              WebElement texts = driver.findElement(By.tagName("staticText"));
              assertEquals(texts.getText(), "some expected value");
          }

          posted on 2013-04-18 10:07 順其自然EVO 閱讀(540) 評論(0)  編輯  收藏 所屬分類: selenium and watir webdrivers 自動化測試學習

          <2013年4月>
          31123456
          78910111213
          14151617181920
          21222324252627
          2829301234
          567891011

          導航

          統計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 申扎县| 宁国市| 尚义县| 江安县| 山阴县| 栾城县| 磐石市| 兰溪市| 贵港市| 达尔| 马山县| 博客| 许昌县| 石棉县| 扎囊县| 中卫市| 察哈| 鄂伦春自治旗| 紫阳县| 同心县| 安宁市| 微山县| 奉化市| 德化县| 维西| 元阳县| 九江县| 江源县| 临洮县| 洛川县| 滨州市| 游戏| 梁山县| 金阳县| 伊春市| 西平县| 焉耆| 房山区| 东莞市| 阳山县| 延川县|