2017-08-02 28 views
1

我一直在閱讀關於蘋果新的和改進的XCTest/UITesting框架,我作爲Android開發人員有一些問題。在Android中,推出一個應用程序,我沒有源代碼,運行UiAutomator我會簡單地使用如何在應用程序上執行UITesting我沒有源代碼?

@Before 
public void setup() { 
    //Init UiDevice instance 
    Instrumentation mInstrumentation = InstrumentationRegistry.getInstrumentation(); 
    mDevice = UiDevice.getInstance(mInstrumentation); 

    //start from home screen on each new test 
    mDevice.pressHome(); 

    //wait for launcher 
    final String launcherPackage = mDevice.getLauncherPackageName(); 
    assertThat(launcherPackage, notNullValue()); 
    mDevice.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), LAUNCH_TIMEOUT); 

    //launch app 
    Context mContext = InstrumentationRegistry.getContext(); 
    final Intent intent = mContext.getPackageManager() 
      .getLaunchIntentForPackage(GMAIL_APP_PACKAGE); 

    //Clear any previous instances 
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); 
    mContext.startActivity(intent); 

    //wait for app to appear 
    mDevice.wait(Until.hasObject(By.pkg(GMAIL_APP_PACKAGE).depth(0)), LAUNCH_TIMEOUT); 
    mDevice.waitForWindowUpdate(null, 5000); 
} 

使用上面的代碼中,我能夠啓動包,那麼我想用UiAutomatorView.bat來檢查元素並獲取其資源ID(或通過文本查找),然後對其執行操作。

在iOS系統中,所有的,我已經找到了中心的測試,你可以訪問源代碼的應用程序的教程。雖然我明白在iOS中編寫這些測試要簡單得多,因爲您只需記錄您希望執行的操作,並且xcode爲您編寫代碼,但我不確定如何將UI測試目標設置爲當前的應用程序安裝在我的設備上。我看了WWDC的視頻,使用這種走過去多應用測試:

var gmailApp: XCUIApplication! 
gmailApp.launchArguments = "-StartFromCleanState", "YES"] 
gmailApp.launch() 

然而,這是行不通的,因爲它沒有目標。

TL; DR:如何設置安裝在我的設備上的應用程序,如Gmail,我的UI測試目標,以及我如何才能啓動的應用程序發現包名?

謝謝!

回答

3

我不相信這是不可能的。

+0

嗯,我希望事實並非如此。我知道有可能使用此方法訪問設置應用或Safari,所以我希望它也可以用於第三方應用。 – Tadhg

+1

出於安全考慮,每個應用程序都安裝在沙箱中,以限制只能訪問應用程序自己的文件,但應用程序可以訪問的特定設備文件和傳感器除外,這些文件和傳感器要求用戶明確許可才能這樣做。一個應用程序不可能以您正在尋找的方式訪問另一個應用程序。更多信息請參閱本:https://developer.apple.com/library/content/documentation/Security/Conceptual/AppSandboxDesignGuide/AppSandboxInDepth/AppSandboxInDepth.html – FightOn

+1

更多的原因:「如果正確沙盒應用程序的惡意代碼獲得控制,它只能訪問應用沙箱中的文件和資源。「另外,應用程序發佈者(例如Google)也可能不希望您擁有該功能。 – FightOn

相關問題