package com.APPtest.class4;
import java.net.URL;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.android.AndroidDriver;
/*@author:WXT
* @time:20170310
* 作用:今日头条的登陆--》话题--》关注--》检查关注是否成功--》打开自己关注的--》推迟
*
*
* */
public class class4_Jrtt {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
AndroidDriver driver;
DesiredCapabilities cap=new DesiredCapabilities();
cap.setCapability("automationName", "Appium");//appium做自动化
// cap.setCapability("app", "C:\software\jrtt.apk");//安装apk
// cap.setCapability("browserName", "chrome");//设置HTML5的自动化,打开谷歌浏览器
cap.setCapability("deviceName", "S4");//设备名称
cap.setCapability("platformName", "Android"); //安卓自动化还是IOS自动化
cap.setCapability("platformVersion", "4.4"); //安卓操作系统版本
cap.setCapability("udid", "192.168.10.101:5555"); //设备的udid (adb devices 查看到的)
cap.setCapability("appPackage", "com.ss.android.article.news");//被测app的包名
cap.setCapability("appActivity", ".activity.MainActivity");//被测app的入口Activity名称
cap.setCapability("unicodeKeyboard", "True"); //支持中文输入
cap.setCapability("resetKeyboard", "True"); //支持中文输入,必须两条都配置
cap.setCapability("noSign", "True"); //不重新签名apk
cap.setCapability("newCommandTimeout", "20"); //没有新命令,appium30秒退出
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),cap);//把以上配置传到appium服务端并连接手机
//隐式等待
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
Thread.sleep(3000);
//1.进入话题模块
driver.findElementByName("话题").click();
driver.findElementByName("关注").click();
// //获取当前混合界面的上下文
Set ContextHandles=driver.getContextHandles();
//
System.out.println(ContextHandles.toString());
driver.context("WEBVIEW_com.ss.android.article.news");
//
WebElement el1=driver.findElementByXPath("/html/body/div/div[3]/div[2]/div[1]/a[3]/div/div[2]/div");
// String title=el1.getText();
// System.out.println("已关注:"+el1.getText());
el1.click();
System.out.println(el1.getText());
driver.context("NATIVE_APP");
WebElement el2=driver.findElementByName("关注");
el2.click();
}
}