杂技
package com.example.test;
import java.io.File;
import java.net.URL;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
public class zhihu {
private AndroidDriver driver;
@Before
public void setUp() throws Exception {
File classpathRoot = new File(System.getProperty("user.dir"));
File appDir = new File(classpathRoot, "apps");
File app = new File(appDir, "zhihu.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("platformName", "Android");
//capabilities.setCapability("deviceName","Android Emulator");
capabilities.setCapability("deviceName","Redmi Note 3");
capabilities.setCapability("platformVersion", "4.3");
//if no need install don't add this
capabilities.setCapability("app", "D:\\Mars_WorkSpace\\ooooo\\apps\\futureve-mobile-update-release-4.13.1(454).apk");
capabilities.setCapability("appPackage", "com.zhihu.android");
//support Chinese
//capabilities.setCapability("unicodeKeyboard" ,"True");
//capabilities.setCapability("resetKeyboard", "True");
//no need sign
//capabilities.setCapability("noSign", "True");
capabilities.setCapability("appActivity", ".app.ui.activity.MainActivity");
// capabilities.setCapability("appActivity",".MainActivity");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
// @Test
public void subiankankan(){
driver.manage().timeouts().implicitlyWait(15,TimeUnit.SECONDS);
//find login button
WebElement loginButton = driver.findElement(By.name("随便看看"));
loginButton.click();
driver.swipe(100, 200, 150, 200, 2000);
}
@Test
public void login(){
driver.manage().timeouts().implicitlyWait(15,TimeUnit.SECONDS);
//find login button
WebElement loginButton = driver.findElement(By.name("登录或注册"));
loginButton.click();
//wait for 20s
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
//find login userName and password editText
List<WebElement> textFieldsList = driver.findElementsByClassName("android.widget.EditText");
textFieldsList.get(0).sendKeys("18959719868");
List<WebElement> textFieldsList2 = driver.findElementsByClassName("android.widget.EditText");
textFieldsList2.get(1).sendKeys("cllcll");
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
//find ok button byName
//driver.findElementByName("OK").click();
// driver.findElement(By.name("登录")).click();;
List<WebElement> buttonFieldsList = driver.findElementsByClassName("android.widget.Button");
buttonFieldsList.get(1).click();
// driver.manage().timeouts().implicitlyWait(90, TimeUnit.SECONDS);
//find keyword 首页 and verify it is display
//Assert.assertTrue( driver.findElement(By.name("首页")).isDisplayed());
}
@After
public void tearDown() throws Exception {
//driver.quit();
driver.closeApp();
driver.resetApp();
}
}
用到的lib
java-client-4.1.2.jar
selenium-java-2.48.2.jar
selenium-java-client-driver-1.0.2.jar
selenium-server-standalone-3.0.1.jar