STB-Tester Python API with other automation tools

180 views
Skip to first unread message

Ken Su

unread,
Jun 23, 2017, 7:33:16 AM6/23/17
to stb-tester

Hi all,

 

I'm trying to wrap up the STB-Tester APIs so I can use them with other automation tools e.g. Selenium, Robot Framework, etc. 

 

And I do notice this blog page on STBT website https://stb-tester.com/blog/2016/09/20/add-visual-verification-to-your-selenium-tests-with-stb-tester

Following the idea from that blog, I successfully empowered my Selenium test with STBT image compare.

 

Now I’m thinking if it would be possible for me to wrap up the Python APIs so they can be available in Robot Framework. I first tried with Robot Framework Selenium2Library + stbt.match and it was working.

However, when I try stbt.press with code

def press_key(key='Home'):
    stbt
.press(key)


I got error message ‘AttributeError: 'NoneType' object has no attribute 'press'’ which I don’ t understand cause if I define

def printer():
   
return dir(stbt)

I can get

['ConfigurationError', 'Frame', 'FrameObject', 'MatchParameters', 'MatchResult', 'MatchTimeout', 'MotionResult', 'MotionTimeout', 'NoVideo', 'OcrMode', 'Position', 'PreconditionError', 'Region', 'TextMatchResult', 'UITestError', 'UITestFailure', '__all__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', '_dut', '_libexecdir', '_stbt', '_vars', 'absolute_import', 'as_precondition', 'debug', 'detect_match', 'detect_motion', 'draw_text', 'frames', 'get_config', 'get_frame', 'init_run', 'is_screen_black', 'match', 'match_all', 'match_text', 'ocr', 'press', 'press_until_match', 'save_frame', 'sys', 'teardown_run', 'wait_for_match', 'wait_for_motion', 'wait_until']
So press should be one of them. Am I missing some config in my script or I'm doing something wrong?

Many thanks

Ken

Lewis Haley

unread,
Jun 23, 2017, 9:13:32 AM6/23/17
to stb-tester
stbt.press is actually a thin wrapper around `_stbt._dut.press`, where `_dut` is an instance of `_stbt.core.DeviceUnderTest` (and in turn this is a wrapper around `_stbt._dut._control.press`). However, this instance is only initialised when calling `stbt.init_run`. To work around, you can instantiate your own `control` object like:

ctrl = _stbt.control.uri_to_remote(<remote uri here/stbt.get_config>)
ctrl
.press('Home')

Ken Su

unread,
Jun 26, 2017, 11:23:30 PM6/26/17
to stb-tester
Hi Lewis,

I didn't know '_stbt.core.DeviceUnderTest' is only initialised when  calling 'stbt.init_run'. Thank you for the explain.

And the workaround you suggested is working like a charm. 

Thank you so much.
Reply all
Reply to author
Forward
0 new messages