与设备上的selendroid服务器通信时出错:

时间:2015-06-16 10:06:48

标签: java eclipse selendroid

我是selendroid的新手,我在脚本执行后遇到跟踪错误。我正在为selendroid工作本机应用程序。

如果有人帮我解决这个问题会很棒!

以下是我的剧本

package com.peddlebuyer.test;

import java.net.URL;
import io.selendroid.SelendroidCapabilities;
import io.selendroid.SelendroidConfiguration;
import io.selendroid.SelendroidDriver;
import io.selendroid.SelendroidLauncher;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.Response;
import org.testng.Assert;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;

import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.touch.FlickAction;
import org.openqa.selenium.interactions.touch.TouchActions;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.AfterMethod;
import java.util.concurrent.TimeUnit;
import java.util.logging.ConsoleHandler;

import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import io.selendroid.waiter.TestWaiter;
import io.selendroid.waiter.WaitingConditions;

public class PeddleBuyer {
private WebDriver driver = null;

@BeforeMethod
public void beforeMethod() throws Exception {

}

@Test
public void assertSellerCanLogin() {
UserDO user = new UserDO("nilofar.jargela@marutitech.com","123456");
try {
        loginUser(user);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
 }

 private void loginUser(UserDO user) throws Exception 
   {

     SelendroidCapabilities capa = new                  SelendroidCapabilities("com.peddle.buyer:1.31");
     driver = new SelendroidDriver(capa);
     capa.setCapability("app-activity", "com.peddle.buyer.SplashActivity");
     capa.setCapability("app-wait-activity", "com.peddle.buyer.BuyerHomeActivity");


    driver.get("and-activity://com.peddle.buyer.BuyerHomeActivity");

    WebDriverWait wait = new WebDriverWait(driver, 60);
    wait.until(ExpectedConditions.presenceOfElementLocated(By.id("onBoardTopContainer")));    
    WebElement pages1 = driver.findElement(By.id("com.peddle.buyer:id/onBoardTopContainer"));
    TouchActions flick1 = new TouchActions(driver).flick(pages1, -100, 0, 0);
    flick1.perform();

    WebElement pages2 = driver.findElement(By.id("com.peddle.buyer:id/onBoardTopContainer"));
    TouchActions flick2 = new TouchActions(driver).flick(pages2, -100, 0, 0);
    flick2.perform();

    WebElement pages3 =   driver.findElement(By.id("com.peddle.buyer:id/onBoardTopContainer"));
    TouchActions flick3 = new TouchActions(driver).flick(pages3, -100, 0, 0);
    flick3.perform();

    driver.findElement(By.linkText("Get started")).click();
    driver.findElement(By.linkText("Log in with Peddle")).click();

    WebElement Email = driver.findElement(By.id("emailInputTextView"));
    Email.sendKeys(user.email);

    driver.findElement(By.id("passwordInput")).sendKeys(user.password);

    driver.findElement(By.linkText("Log in")).click();


    //WebDriverWait wait = new WebDriverWait(driver, 60);
    //wait.until(ExpectedConditions.presenceOfElementLocated(By.id("taskIdText")));
   // wait.until(ExpectedConditions.presenceOfElementLocated(By.linkText("Buy")));
   // wait.until(ExpectedConditions.presenceOfElementLocated(By.linkText("Pass")));
    //wait.until(ExpectedConditions.presenceOfElementLocated(By.id("taskThumbImage")));
   // wait.until(ExpectedConditions.presenceOfElementLocated(By.id("infoButton")));
   // wait.until(ExpectedConditions.presenceOfElementLocated(By.id("footerShadowLayout")));

    capa.setCapability("app-activity", "com.peddle.buyer.BuyerHomeActivity");
    capa.setCapability("app-wait-activity", "com.peddle.buyer.TaskInformationActivity");
    driver.get("and-activity://com.peddle.buyer.TaskInformationActivity");



}

@AfterMethod
public void afterMethod() {

    //driver.quit();
 }

}

我还创建了UserDO.java

package com.peddlebuyer.test;

 public class UserDO {

 public String email;
 public String password;

 public UserDO(String email, String password) {
        super();
        this.email = email;
        this.password = password;
   }

 }

我收到以下错误:

E/AndroidRuntime( 1190): FATAL EXCEPTION: main
E/AndroidRuntime( 1190): java.lang.RuntimeException: Unable to start        activity Co
mponentInfo{com.peddle.buyer/com.peddle.buyer.TaskInformationActivity}:   java.lang.NullPointerException

1 个答案:

答案 0 :(得分:0)

在测试开始运行之前,您没有初始化服务器 将以下代码放入@BeforeMethod带注释的方法

SelendroidCapabilities capa = new SelendroidCapabilities("com.peddle.buyer:1.31");
driver = new SelendroidDriver(capa);
capa.setCapability("app-activity", "com.peddle.buyer.SplashActivity");
capa.setCapability("app-wait-activity", "com.peddle.buyer.BuyerHomeActivity");