xiaocong / uiautomator

Python wrapper of Android uiautomator test tool.
MIT License
2.03k stars 638 forks source link

how to set the value of seekbar by uiautomator? #181

Open BigWavelet opened 7 years ago

BigWavelet commented 7 years ago

RT! image

siva-kranthi commented 7 years ago

It would be impossible to seek it to particular frame/time. But you can seek it to random point & verify the expected result

BigWavelet commented 7 years ago

maybe i can calculate the expected value according to the position of the seekbar, and then click or swipe? @SivaKranthiKumar

siva-kranthi commented 7 years ago

Yes, you can do that if it is possible :)

sanjaykumar5115 commented 7 years ago

Hi Siva,

Can share the example how can we do this.

siva-kranthi commented 7 years ago

@sanjaykumar5115 get the seekbar co-ordinates using obj.info. No find random co-ordinates of the seekbar by just increasing/decreasing the x-axis values

sanjaykumar5115 commented 7 years ago

Hi,

Thanks for your quick reply. we have used the same approach, but this is varying device to device. On old android version device(4.2.2) it is partially working, but on new android version device(6.0) , nothing is working. Can you share an example, which will work on every device. At lest share the an example?

AkivaGit commented 7 years ago

I found alternative way to control seekbar, since I also found the standard methods hard to use because of some problems, so here it is, maybe it will help you:

private void clickSeekbar (float position) { while ((seekBarUiObj2 = mDevice.findObject(By.res(BASIC_SAMPLE_PACKAGE+":id/seekbar"))) == null) { mDevice.click(200,200); try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } } Rect rect = seekBarUiObj2.getVisibleBounds(); mDevice.click(rect.left+5/pixels/+(int)((rect.right-rect.left-10/pixels/)*position), ((rect.top+rect.bottom)/2));

}

The trick is to click on the device on the desired location on the seekbar. It works. The whlle loop makes sure the seekbar is on screen, if not tap the screen on some location, which makes seekbar to appear. Then calculate the location to be clicked according to desired position. Only if your seekbar is very thin like 1 or 2 pixels it might not work.