2014-10-01 15 views
14

Ứng dụng đang chuyển qua các bài kiểm tra espresso tại địa phương, tôi có nghĩa là trực tiếp với các thiết bị và bộ giả lập genymotion. Khi tôi sử dụng Jenkins để xây dựng hình ảnh của ứng dụng. Bài kiểm tra espresso không thành công tôi nhận được lỗi này.testUI (Jenkins) sử dụng espresso

JENKINS:

java.lang.RuntimeException: Waited for the root of the view hierarchy to have window focus and not be requesting layout for over 10 seconds. If you specified a non default root matcher, it may be picking a root that never takes focus. Otherwise, something is seriously wrong. Selected Root: 
Root{[email protected], [email protected], has-window-focus=false, layout-params-type=1, layout-params-string=WM.LayoutParams{(0,0)(fillxfill) sim=#100 ty=1 fl=#1810100 pfl=0x8 wanim=0x103028f}, decor-view-string=DecorView{id=-1, visibility=VISIBLE, width=800, height=1184, has-focus=true, has-focusable=true, has-window-focus=false, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1}} 
. All Roots: 
Root{[email protected], [email protected], has-window-focus=false, layout-params-type=1, layout-params-string=WM.LayoutParams{(0,0)(fillxfill) sim=#100 ty=1 fl=#1810100 pfl=0x8 wanim=0x103028f}, decor-view-string=DecorView{id=-1, visibility=VISIBLE, width=800, height=1184, has-focus=true, has-focusable=true, has-window-focus=false, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1}} 
at com.google.android.apps.common.testing.ui.espresso.base.RootViewPicker.get(RootViewPicker.java:84) 
at com.google.android.apps.common.testing.ui.espresso.ViewInteractionModule.provideRootView(ViewInteractionModule.java:51) 
at com.google.android.apps.common.testing.ui.espresso.ViewInteractionModule$$ModuleAdapter$ProvideRootViewProvidesAdapter.get(ViewInteractionModule$$ModuleAdapter.java:187) 
at com.google.android.apps.common.testing.ui.espresso.ViewInteractionModule$$ModuleAdapter$ProvideRootViewProvidesAdapter.get(ViewInteractionModule$$ModuleAdapter.java:151) 
at com.google.android.apps.common.testing.ui.espresso.base.ViewFinderImpl.getView(ViewFinderImpl.java:52) 
at com.google.android.apps.common.testing.ui.espresso.ViewInteraction$2.run(ViewInteraction.java:141) 
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:442) 
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305) 
at java.util.concurrent.FutureTask.run(FutureTask.java:137) 
at android.os.Handler.handleCallback(Handler.java:615) 
at android.os.Handler.dispatchMessage(Handler.java:92) 
at android.os.Looper.loop(Looper.java:137) 
at android.app.ActivityThread.main(ActivityThread.java:4745) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
at dalvik.system.NativeStart.main(Native Method) 
+0

Dấu vết ngăn xếp này là gì? – yogurtearl

+0

đó là những gì jenkins nói. – Alfaplus

+0

Dấu vết ngăn xếp đó là từ Espresso chạy trên trình giả lập Android hoặc thiết bị Android. Bạn đang chạy giả lập trên máy chủ Jenkins của bạn? – yogurtearl

Trả lời

10

stacktrace nghĩa là Espresso không thể tìm thấy cửa sổ ứng dụng. Trong khi thử nghiệm trên màn hình giả lập thường ẩn đằng sau Screen Lock. Bạn cần sử dụng một số mã để vô hiệu hóa ScreenLock theo chương trình. Cách thuận tiện nhất để tôi mở khóa màn hình là sử dụng Robotium. Nó có phương thức solo.unlockScreen(). Tôi đã đặt nó vào phương thức setUp() của vòng đời kiểm tra.

Links: https://github.com/RobotiumTech/robotium/blob/master/robotium-solo/src/main/java/com/robotium/solo/Solo.java

+2

Trên đầu trang của phản ứng của scytale - bạn cũng có thể cung cấp một ví dụ đơn giản về việc thực hiện mà bạn đang đề xuất. – g00dy

1

Giải pháp là để tạo ra một Á hậu kiểm tra tùy chỉnh để mở khóa màn hình và bắt đầu một khóa trỗi dậy cho đến khi các cuộc thử nghiệm được thực hiện.

public class TestRunner extends android.support.test.runner.AndroidJUnitRunner 
{ 
    private PowerManager.WakeLock mWakeLock; 

    @Override 
    public void callApplicationOnCreate(Application app) 
    { 
     // Unlock the screen 
     KeyguardManager keyguard = (KeyguardManager) app.getSystemService(Context.KEYGUARD_SERVICE); 
     keyguard.newKeyguardLock(getClass().getSimpleName()).disableKeyguard(); 

     // Start a wake lock 
     PowerManager power = (PowerManager) app.getSystemService(Context.POWER_SERVICE); 
     mWakeLock = power.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, getClass().getSimpleName()); 
     mWakeLock.acquire(); 

     super.callApplicationOnCreate(app); 
    } 

    @Override 
    public void onDestroy() 
    { 
     mWakeLock.release(); 

     super.onDestroy(); 
    } 
} 

Sau đó AndroidManifest.xml các bài kiểm tra của bạn và thêm các quyền cần thiết:

<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/> 
<uses-permission android:name="android.permission.WAKE_LOCK"/> 

Đừng quên để chỉnh sửa build.gradle của bạn để sử dụng lớp mới testInstrumentationRunner.

Source

+0

Giải pháp này sử dụng một số phương pháp và hằng số không được chấp nhận. Bạn có thể cung cấp một số thay thế? – MeLine

0

Từ quan điểm của tôi, bạn cần phải sắp xếp công việc Jenkins của bạn theo cách sau: trước khi chạy thử nghiệm Espresso (tôi giả sử bạn có connectedAndroidTest trong một gradle sau xây dựng hành động đó hoặc một cái gì đó như thế này) , thêm hành động hậu xây dựng để gỡ cài đặt gói ứng dụng và một gói khác để gỡ cài đặt gói thử nghiệm ứng dụng. Ví dụ: com.example.mypackage.debug và com.example.mypackage.debug.test. Đây là một cách hay để làm mới ứng dụng vào điện thoại thông minh/trình giả lập của bạn, để cho phép Espresso sử dụng phép thuật của nó.

Cũng đảm bảo rằng bạn có tùy chọn Luôn bật trong Công cụ dành cho nhà phát triển được kích hoạt (tùy thuộc vào thiết bị, trong Cài đặt bạn có tùy chọn Nhà phát triển hoặc menu phụ Công cụ dành cho nhà phát triển).

Nếu không có cách nào trong số này hoạt động, điều đó có nghĩa là ở đâu đó trong công việc Jenkins của bạn, bạn có một số thứ tự hành động và cần được làm rõ. Đối với tôi, việc gỡ cài đặt các gói đã giúp tôi làm sạch hệ thống của tất cả những thứ liên quan đến ứng dụng của tôi.

Hy vọng nó cũng sẽ phù hợp với bạn.

Nếu không, vui lòng viết bình luận và tôi sẽ giúp bạn.

Chúc may mắn!

0

Tôi khuyên bạn nên sử dụng Test-Butler, để tắt hoạt ảnh và mở khóa màn hình trong khi thử nghiệm.

+0

Test-Butler chỉ có thể được sử dụng cho trình giả lập, vì vậy bạn nên sử dụng trình giả lập để chạy thử nghiệm của mình. Nếu bạn đang thử nghiệm trên các thiết bị thực, tôi sẽ đề nghị 'UiAutomator'. – carvaq

Các vấn đề liên quan