Appium_Java code(1)

import java.io.File;
import java.net. MalformedURLException;
import java.net.URL;
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.WebDriver;
import org.openqa.selenium.remote. CapabilityType;
import org.openqa.selenium.remote. DesiredCapabilities;
import org.openqa.selenium.remote. RemoteWebDriver;
import org.openqa.selenium.support. ui.ExpectedConditions;
import org.openqa.selenium.support. ui.WebDriverWait;


public class AndroidExample {
WebDriver driver = null;
    
    @Before
     public void setup() throws MalformedURLException {
            File appDir = new File("C:\\Users\\NZIA\\ android_sdk\\sdk\\tools\\apps\ \SdkController\\bin");
File app = new File(appDir, "SdkControllerApp.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(" device","Android");
capabilities.setCapability( CapabilityType.BROWSER_NAME, "");
capabilities.setCapability( CapabilityType.VERSION, "4.4");
capabilities.setCapability( CapabilityType.PLATFORM, "WINDOWS");
            // Here we mention the app's package name, to find the package name we  have to convert .apk file into java class files
capabilities.setCapability(" app-package","com.android. tools.sdkcontroller. activities");
            //Here we mention the activity name, which is invoked initially as app's first page.
capabilities.setCapability(" app-activity","MainActivity");
//capabilities.setCapability(" app-wait-activity"," LoginActivity, NewAccountActivity");
capabilities.setCapability(" app", app.getAbsolutePath());

driver = new RemoteWebDriver(new URL(" http://127.0.0.1:4723/wd/hub "), capabilities);
driver.manage().timeouts(). implicitlyWait(80, TimeUnit.SECONDS);  

     }

   @Test
public void loginTest() throws Exception {

driver.findElement(By.xpath("/ /EditText[@text='Email Address']")).sendKeys(" tes...@gmail.com ");
driver.findElement(By.xpath("/ /LinearLayout/EditText[2]")). sendKeys("Testerpwd");
driver.findElement(By.xpath("/ /CheckBox")).click();
driver.findElement(By.xpath("/ /Button[@text='Login']")). click();

WebDriverWait wait = new WebDriverWait(driver,80);
wait.until(ExpectedConditions. presenceOfElementLocated(By. xpath("//Button[@text='Logout' ]")));  
driver.findElement(By.xpath("/ /Button[@text='Logout']")). click(); 

    }

   @After
    public void tearDown() {
           driver.quit();
    }


}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值