1. 程式人生 > >Java練習-002

Java練習-002

java

package com.syswin.first;

/**

* @author YuFeifei

* @version 2017年11月14日 上午9:12:08

* 類說明:第一個啟動類

*/

import io.appium.java_client.android.AndroidDriver;

import java.io.File;

import java.net.MalformedURLException;

import java.net.URL;

import org.openqa.selenium.remote.DesiredCapabilities;

import org.testng.annotations.AfterSuite;

import org.testng.annotations.BeforeSuite;

import org.testng.annotations.Test;


import com.appium.test.TestngListener;


public class AppiumTestCase {

private AndroidDriver driver;

public AndroidDriver getDriver() {

return driver;

}

public void setDriver(AndroidDriver driver) {

this.driver = driver;

}

@BeforeSuite

public void beforeSuite() throws MalformedURLException{

//set up appium

File classpathRoot = new File(System.getProperty("user.dir"));//獲取當前路徑

File appDir = new File(classpathRoot,"apk");//獲取apk文件夾的路徑

File app = new File(appDir,"Toon-beijing-test.apk");//獲取要測試的APP

DesiredCapabilities capabilities = new DesiredCapabilities();//創建DesiredCapabilities對象

capabilities.setCapability("platformName", "Android");//手機操作系統

capabilities.setCapability("deviceName", "test");//真機名稱,目前Android不起作用

capabilities.setCapability("platformVersion", 4.3);//Android系統版本

//capabilities.setCapability("app", app.getAbsolutePath());//在手機上安裝APP

capabilities.setCapability("appPackage", "com.systoon.beijingtoon");//package

capabilities.setCapability("appActivity", "com.systoon.toon.user.login.view.WelcomeActivity");

capabilities.setCapability("unicodeKeyboard", "Ture");//輸入中文

capabilities.setCapability("resetKeyboard", "Ture");

driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);

}

@AfterSuite

public void afterSuite(){

driver.quit();

}

@Test

public void testMoment() throws Exception{

Thread.sleep(6000);

driver.findElementById("com.systoon.beijingtoon:id/main_tab_icon").click(); //消息tab

driver.findElementById("com.systoon.beijingtoon:id/main_tab_icon").click() ; //消息tab

driver.findElementById("com.systoon.beijingtoon:id/tv_change_to_trend").click(); //動態

Thread.sleep(2000);

driver.findElementById("com.systoon.beijingtoon:id/trends_home_page_float_button").click(); //發布

driver.findElementById("com.systoon.beijingtoon:id/content_richedit_input").sendKeys("發布的第一個動態");

Thread.sleep(2000);

driver.findElementById("com.systoon.beijingtoon:id/content_item_picture_selected").click(); //添加照片

Thread.sleep(2000);

driver.findElementById("com.systoon.beijingtoon:id/trends_view_select_sort_item_btn").click(); //拍攝

Thread.sleep(2000);

driver.findElementById("com.systoon.beijingtoon:id/trends_video_rec_in_iv").click(); //拍攝

Thread.sleep(2000);

driver.findElementById("com.systoon.beijingtoon:id/trend_video_finish_rl").click(); //選中

driver.findElementById("com.systoon.beijingtoon:id/rich_normal_location_layout").click(); //所在位置

Thread.sleep(2000);

driver.findElementById("com.systoon.beijingtoon:id/tv_item_plugin_map_listview_addr").click(); //海南地產

Thread.sleep(2000);

driver.findElementById("com.systoon.beijingtoon:id/title_right_bt_id").click(); //確定

driver.findElementById("com.systoon.beijingtoon:id/title_right_bt_id").click(); //發送

}


}


Java練習-002