简体   繁体   English

Robotium - 检测从屏幕上画出来的物体

[英]Robotium - detect objects drawn off screen

So I made a change to my Android app last week and inadvertently made some buttons get drawn outside the screen.所以我上周对我的 Android 应用程序进行了更改,无意中将一些按钮绘制到了屏幕之外。

I could see the objects off screen in Eclipse alright and no errors were thrown but when the app ran the buttons were not visible (off screen).我可以在 Eclipse 中看到屏幕外的对象,并且没有抛出任何错误,但是当应用程序运行时,按钮不可见(屏幕外)。

Just wondering will Robotium catch this or will the buttons still be "pressable".只是想知道 Robotium 会捕捉到这个还是按钮仍然可以“按下”。

My question is, given the above scenario, I run a Robotium test to select a button that is no longer drawn/visible inside the screen.我的问题是,鉴于上述情况,我运行 Robotium 测试以选择一个不再在屏幕内绘制/可见的按钮。 Will Robotium still be able to select the button and pass the test or will it fail becuase the button is no longer on screen? Robotium 是否仍然能够选择按钮并通过测试,还是会因为按钮不再出现在屏幕上而失败?

Visibility能见度

The visibility option is asserted with a snippet like below.可见性选项使用如下代码段断言。 Note that getVisibility will return an integer from 0=VISIBLE to 8=GONE with 4=INVISIBLE.请注意,getVisibility 将返回一个从 0=VISIBLE 到 8=GONE 的整数,其中 4=INVISIBLE。 More information at Android API Javadoc for View .更多信息见Android API Javadoc for View

int expectedValue = 0; // 0=VISIBLE, 4=INVISIBLE, 8=GONE
assertEquals("Message when assert failed", expectedValue, 
    solo.getView(your.project.package.R.id.someViewId).getVisibility());

LocationOnScreen屏幕位置

Visibility will not always be enough to check if something is visible or not on the screen.可见性并不总是足以检查屏幕上是否可见。 Something can be visible while drawn off the screen or with a negative width.从屏幕上或负宽度绘制时可以看到某些内容。 To verify that you can use the getLocationOnScreen() method .验证您是否可以使用getLocationOnScreen() 方法 It will return the x and y coordinates (in that order) of the view on the screen.它将返回屏幕上视图的 x 和 y 坐标(按该顺序)。 An example:一个例子:

int] location = new int[2]; // this will hold the x and y position
// retrieve coordinates
solo.getView(your.project.package.R.id.someViewId).getLocationOnScreen(location);
// and check if possitive or whatever fits your needs
assertTrue("Message when assert failed", location[0] >= 0 && location[1] >= 0);

This should properly detect your off screen buttons.这应该可以正确检测到您的屏幕外按钮。

如果您尝试单击屏幕上未绘制/不可见的按钮,Robotium 将使测试用例失败。

As far as I know, you can press the buttons if they are drawn, even if they are not visible.据我所知,如果按钮被绘制,即使它们不可见,你也可以按下它们。 Eg, you can press buttons in a scrollable view of which only some parts are visible.例如,您可以在仅某些部分可见的可滚动视图中按下按钮。 The important thing for robotium is that is can find the buttons you want to click somethere within the views of the current activity (it somehow internally traverses the view and searches for widgets in all its subwidgets).对于 Robotium 来说,重要的是可以在当前活动的视图中找到您想要单击的按钮(它以某种方式在内部遍历视图并在其所有子小部件中搜索小部件)。

Robotium can press buttons off the screen but depending on how you search for the button it may or may not find it. Robotium 可以按下屏幕外的按钮,但取决于您搜索按钮的方式,它可能会也可能不会找到它。 Confusing right?混淆对吗?

Robotium internally sometimes checks for the visibility of Views before returning them eg when you ask for all the buttons, but if you use different techniques or findById() then it will not in fact perform the same checks. Robotium 有时会在内部检查视图的可见性,然后再返回它们,例如当您要求所有按钮时,但如果您使用不同的技术或 findById() 那么它实际上不会执行相同的检查。 You can however just use the visibility checks that are inside robotium in order to validate that it is visible or not!但是,您可以仅使用机器人内部的可见性检查来验证它是否可见!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM