无法启动实际的应用程序,但加载helloworld

时间:2016-02-22 01:24:24

标签: java android mobile automation appium

运行我的脚本后,我将看到此处显示的屏幕:

enter image description here

当我尝试实际启动selenroid应用程序时,任何人都可以让我知道为什么我从以下脚本调用的应用程序没有启动?

testthis.java代码(在第二个包名下):

package demolaunchtest;
import io.appium.java_client.android.AndroidDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
public class testthis {
public static AndroidDriver driver;
@BeforeClass
public void setUP() throws MalformedURLException {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("device", "Android");
    capabilities.setCapability("deviceName", "Lokesh Gangaiah");
    capabilities.setCapability("platformName", "Android");
    capabilities.setCapability("platformVersion", "5.0");


    capabilities.setCapability("appPackage", "io.selendroid.testapp");
    capabilities.setCapability("appActivity", "io.selendroid.testapp.HomeScreenActivity");

    driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
 @Test
public void Sel_Button_Test() throws InterruptedException {

    System.out.println("Test Started");

    WebElement ButtonElement = driver.findElementById("io.selendroid.testapp:id/buttonStartWebview");
    ButtonElement.click();

    Thread.sleep(3000L);

    System.out.println("Test has been completed");

}


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

}

MainActivity.java - 在第一个包下:

package com.example.demo;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

}

AndroidMainfest.xml代码:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.demo"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="21" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

Appiumg日志:它没有报告任何错误:

  

info:欢迎使用Appium v​​1.4.16(REV ae6877eff263066b26328d457bd285c0cc62430d)   info:Appium REST http接口监听器在127.0.0.1:4723上启动   info:[debug]非默认服务器args:{“address”:“127.0.0.1”,“logNoColors”:true,“deviceName”:“Lokesh Gangaiah”,“platformName”:“Android”,“platformVersion”:“ 21" , “automationName”: “Appium”, “语言”: “恩”, “现场”: “AU”}   info:Console LogLevel:debug

eclipse控制台中的日志:

  

Android发布!   adb正常运行。   执行com.example.myapp1.MainActivity活动启动   将myapp1.apk上传到设备'00bd9781'   安装myapp1.apk ......   成功!   在设备00bd9781上启动com.example.myapp1.MainActivity活动   ActivityManager:开始:Intent {act = android.intent.action.MAIN cat = [android.intent.category.LAUNCHER] cmp = com.example.myapp1 / .MainActivity}

1 个答案:

答案 0 :(得分:0)

在向您的#Install and call simsem and psych package, to simulate datasets based on population model, and fit fa model install.packages("simsem") library(simsem) install.packages("psych") library(psych) #Specify Population Model popModel<-" f1 =~ 0.7*y1 + 0.7*y2 + 0.7*y3 f2 =~ 0.5*y4 + 0.5*y5 + 0.5*y6 f1 ~~ 1*f1 f2 ~~ 1*f2 f1 ~~ 0.50*f2 y1 ~~ 0.51*y1 y2 ~~ 0.51*y2 y3 ~~ 0.51*y3 y4 ~~ 0.75*y4 y5 ~~ 0.75*y5 y6 ~~ 0.75*y6 " #Function: User specifies number of reps, sample size, number of factors, rotation and extraction method #Then for each rep, a random sample of popModel is drawn, a FA model is fit, and two logical values are saved #in data.frame fit sample.efa = function(rep, N, nfac, rotation, extract){ fit = data.frame(RMSEA= logical(0), TLI = logical(0)) #create empty data frame with two columns for(i in seq_len(rep)){ dat = generate(popModel, N) #draw a random sample of N size from popModel model = fa(dat, nfactors = nfac, rotate = rotation, fm = extract, SMC = TRUE, alpha = .05) #fit FA model with user specified options from function store = data.frame(RMSEA=all(model$rms < .08), TLI = all(model$TLI > .90)) #save two logical values in "store" names(store) = names(fit) #give "store" same names as target data-frame fit=rbind(fit, store) #save values from each iteration of "store" in target data-frame "fit" } } #Run test of function with small number of reps (5) of sample sizes of 200 set.seed(123) sample.efa(5, N = 200, nfac = 2, rotation = "promax", extract = "ml") (在您的情况下为capabilities)提供AppiumDriver时,您要创建自动化测试套件的应用程序是使用以下功能指定的,请在评论中提及您提供的价值是正确的:

AndroidDriver

有关功能的更多详细信息,请参阅Docs on appium.io for capabilities.

所以这就是问题的原因,你一直在使用selendroid的示例包来运行你的测试,同时期望你自己建立的apk出现。您可以更正以下内容 -

capabilities.setCapability(MobileCapabilityType.APP, "<path to the application>"); // adding this should help
// Specific to Android application
capabilities.setCapability(MobileCapabilityType.APP_PACKAGE, "<package name of the app>"); // your case 'io.selendroid.testapp'
capabilities.setCapability(MobileCapabilityType.APP_ACTIVITY, "<activity name you want to launch on the app to start>"); // your case 'io.selendroid.testapp.HomeScreenActivity'

我希望你这样做,你也可以提供你的应用程序目录的正确路径,并使用同一个包中的MobileCapabilityType.APP_PACKAGE : com.example.demo (line 1 from MainActivity.java and line 2 from AndroidManifest.xml) MobileCapabilityType.APP_ACTIVITY : com.example.demo.MainActivity (from manifest file again <activity android:name=".MainActivity"..../>