How to use _reduce_degrees method in robotframework-ioslibrary

Best Python code snippet using robotframework-ioslibrary_python

__init__.py

Source:__init__.py Github

copy

Full Screen

...272 if fail:273 raise IOSLibraryException('playback failed because: %s' % error_msg)274 return res275 def _rotate_to(self, orientation, direction="left"):276 orientation = self._reduce_degrees(orientation)277 self._current_orientation = orientation278 if direction == "right":279 orientation += 90280 elif direction == "left":281 orientation += 270282 orientation = self._reduce_degrees(orientation)283 orientation = ORIENTATIONS_REV[orientation]284 playback = "rotate_%s_home_%s" % (direction, orientation)285 self._playback(playback)286 time.sleep(1)287 def _reduce_degrees(self, degrees):288 while degrees >= 360:289 degrees -= 360290 while degrees < 0:291 degrees += 360292 return degrees293 def _element_exists(self, query):294 if not self.query(query):295 return False296 return True297 def _get_webview_html(self, query=None, index=None):298 if not index: index = 0299 if not query: query = ""300 res = self.query("webView " + (query and query + " " or "") + "css:'body'")301 index = int(index)302 if not res or not res[index]:303 raise IOSLibraryException("No WebView with index %i found" % index)304 return res[index]["html"]305 def query(self, query):306 """307 Search for a UIElement matching `query`308 `query` query selector. The available syntax is documented here https://github.com/calabash/calabash-ios/wiki/05-Query-syntax309 """310 return self._map(query, "query")311 def query_all(self, query):312 """313 Search for all UIElements matching `query`314 `query` query selector. The available syntax is documented here https://github.com/calabash/calabash-ios/wiki/05-Query-syntax315 """316 return self._map(query, "query_all")317 def _pinch(self, in_out, options={}):318 f = "pinch_in"319 if in_out == "out":320 f = "pinch_out"321 self._playback(f, options)322 # BEGIN: STOLEN FROM SELENIUM2LIBRARY323 def _get_log_dir(self):324 logfile = GLOBAL_VARIABLES['${LOG FILE}']325 if logfile != 'NONE':326 return os.path.dirname(logfile)327 return GLOBAL_VARIABLES['${OUTPUTDIR}']328 def _get_screenshot_paths(self, filename):329 logdir = self._get_log_dir()330 if not filename:331 self._screenshot_index += 1332 filename = 'ios-screenshot-%d.png' % self._screenshot_index333 filename = os.path.join('screenshots', filename)334 screen_dir = os.path.join(logdir, 'screenshots')335 if not os.path.exists(screen_dir):336 os.mkdir(screen_dir)337 else:338 filename = filename.replace('/', os.sep)339 path = os.path.join(logdir, filename)340 link = robot.utils.get_link_path(path, logdir)341 return path, link342 # END: STOLEN FROM SELENIUM2LIBRARY343 # DEFINITIONS344 def touch(self, query):345 """346 Touch element specified by query347 `query` selector of the element to touch. The available syntax is documented here https://github.com/calabash/calabash-ios/wiki/05-Query-syntax348 """349 return self._playback("touch", {"query": query})350 def touch_position(self, x=0, y=0):351 """352 Simulate a touch at the specified position353 `x` X-Coordinate of the position to touch354 `y` Y-Coordinate of the position to touch355 """356 self._playback("touch",357 {"offset": {358 "x": x,359 "y": y360 }361 })362 def capture_screenshot(self, filename=None, relative_url='screenshot'):363 """364 Captures a screenshot of the current screen and embeds it365 in the test report366 `filename` Location where the screenshot will be saved. If omitted a unique filename will be chosen.367 `relative_url` URL part, relative to the device endpoint. For the standard setup the default value is sufficient.368 """369 self._screenshot(filename, relative_url)370 def toggle_switch(self, name=None):371 """372 Toggle a switch373 `name` Name of the switch to toggle.374 """375 if not name:376 self.touch("switch")377 else:378 self.touch("switch marked:'%s'" % name)379 def touch_text(self, placeholder=None):380 """381 Touch a Textfield382 `placeholder` of textField to touch383 """384 if not placeholder:385 self.touch("textField")386 else:387 self.touch("textField placeholder:'%s'" % placeholder)388 def set_text(self, value, query="textField"):389 """390 Set the value of a textField391 `value` the new value of the textField392 `query` query selector to find the textField that will be set to the new value393 """394 text_fields_modified = self._map(query, "setText", [value])395 if not text_fields_modified:396 raise IOSLibraryException("could not find text field %s" % query)397 def go_back(self):398 """399 Touch the first Navigationitem in a Navigation Bar400 """401 self.touch("navigationItemButtonView first")402 def rotate(self, direction):403 """404 Rotate the simulator405 `direction` The direction to rotate the simulator in. Valid values are "left" and "right".406 """407 if direction == "right":408 self._current_orientation -= 90409 elif direction == "left":410 self._current_orientation += 90411 else:412 raise IOSLibraryException("not a valid direction %s" % direction)413 self._rotate_to(self._current_orientation, direction)414 def set_device_orientation_to(self, orientation, direction="left"):415 """416 Set orientation of the simulator417 `orientation` The final orientation the simulator should have afterwards. Valid values are "up", "down", "left", "right".418 `direction` The direction to rotate the simulator in until it reached the final orientation. Valid values are "left" and "right".419 """420 degrees = ORIENTATIONS[orientation]421 self._rotate_to(degrees, direction)422 def scroll(self, direction, query="scrollView index:0"):423 """424 Scroll the view.425 `direction` direction to scroll in. Valid values are "up", "down", "left", "right"426 `query` selector of the view to scroll in. Defaults to the first scrollView.427 """428 views_touched = self._map(query, "scroll", [direction])429 if not views_touched:430 raise IOSLibraryException("could not find view to scroll: %s" %431 query)432 def pinch(self, direction, query=None):433 """434 Pinch in or out.435 `direction` to pinch. Valid values are "in" and "out".436 `query` selector of the element to pinch on437 """438 options = {}439 if query:440 options = {"query": query}441 self._pinch(direction, options)442 def swipe(self, direction, query=None):443 """444 Swipe.445 `direction` The direction to swipe in. Valid values are "up", "down", "left", "right"446 `query` query identifiying the element of the screen to be swiped on, e.g. "view marked:'foo'"447 """448 degrees = ORIENTATIONS[direction]449 direction = (360 - self._current_orientation) + degrees450 direction = self._reduce_degrees(direction)451 direction = ORIENTATIONS_REV[direction]452 options = {}453 if query:454 options["query"] = query455 self._playback("swipe_%s" % direction, options)456 def screen_should_contain_text(self, expected):457 """458 Asserts that the current screen contains a given text459 `expected` The text that should be on the screen460 """461 if not self._element_exists("view {text LIKE '*%s*'}" %462 expected.replace("'", r"\'")):463 raise IOSLibraryException("No text %s found" % expected)464 def screen_should_contain(self, expected):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run robotframework-ioslibrary automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful