How to use watchers method in uiautomator

Best Python code snippet using uiautomator

watchlists_unittest.py

Source: watchlists_unittest.py Github

copy

Full Screen

1#!/​usr/​bin/​env python2# Copyright (c) 2011 The Chromium Authors. All rights reserved.3# Use of this source code is governed by a BSD-style license that can be4# found in the LICENSE file.5"""Unit tests for watchlists.py."""6# pylint: disable=E1103,no-value-for-parameter,protected-access7import os8import sys9import unittest10sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))11from third_party import mock12import watchlists13class WatchlistsTest(unittest.TestCase):14 def setUp(self):15 super(WatchlistsTest, self).setUp()16 mock.patch('watchlists.Watchlists._HasWatchlistsFile').start()17 mock.patch('watchlists.Watchlists._ContentsOfWatchlistsFile').start()18 mock.patch('watchlists.logging.error').start()19 self.addCleanup(mock.patch.stopall)20 def testMissingWatchlistsFileOK(self):21 """Test that we act gracefully if WATCHLISTS file is missing."""22 watchlists.Watchlists._HasWatchlistsFile.return_value = False23 wl = watchlists.Watchlists('/​some/​random/​path')24 self.assertEqual(wl.GetWatchersForPaths(['some_path']), [])25 def testGarbledWatchlistsFileOK(self):26 """Test that we act gracefully if WATCHLISTS file is garbled."""27 contents = 'some garbled and unwanted text'28 watchlists.Watchlists._HasWatchlistsFile.return_value = True29 watchlists.Watchlists._ContentsOfWatchlistsFile.return_value = contents30 wl = watchlists.Watchlists('/​a/​path')31 self.assertEqual(wl.GetWatchersForPaths(['some_path']), [])32 def testNoWatchers(self):33 contents = \34 """{35 'WATCHLIST_DEFINITIONS': {36 'a_module': {37 'filepath': 'a_module',38 },39 },40 'WATCHLISTS': {41 'a_module': [],42 },43 } """44 watchlists.Watchlists._HasWatchlistsFile.return_value = True45 watchlists.Watchlists._ContentsOfWatchlistsFile.return_value = contents46 wl = watchlists.Watchlists('/​a/​path')47 self.assertEqual(wl.GetWatchersForPaths(['a_module']), [])48 def testValidWatcher(self):49 watchers = ['abc@def.com', 'x1@xyz.org']50 contents = \51 """{52 'WATCHLIST_DEFINITIONS': {53 'a_module': {54 'filepath': 'a_module',55 },56 },57 'WATCHLISTS': {58 'a_module': %s,59 },60 } """ % watchers61 watchlists.Watchlists._HasWatchlistsFile.return_value = True62 watchlists.Watchlists._ContentsOfWatchlistsFile.return_value = contents63 wl = watchlists.Watchlists('/​a/​path')64 self.assertEqual(wl.GetWatchersForPaths(['a_module']), watchers)65 def testMultipleWatchlistsTrigger(self):66 """Test that multiple watchlists can get triggered for one filepath."""67 contents = \68 """{69 'WATCHLIST_DEFINITIONS': {70 'mac': {71 'filepath': 'mac',72 },73 'views': {74 'filepath': 'views',75 },76 },77 'WATCHLISTS': {78 'mac': ['x1@chromium.org'],79 'views': ['x2@chromium.org'],80 },81 } """82 watchlists.Watchlists._HasWatchlistsFile.return_value = True83 watchlists.Watchlists._ContentsOfWatchlistsFile.return_value = contents84 wl = watchlists.Watchlists('/​a/​path')85 self.assertEqual(wl.GetWatchersForPaths(['file_views_mac']),86 ['x1@chromium.org', 'x2@chromium.org'])87 def testDuplicateWatchers(self):88 """Test that multiple watchlists can get triggered for one filepath."""89 watchers = ['someone@chromium.org']90 contents = \91 """{92 'WATCHLIST_DEFINITIONS': {93 'mac': {94 'filepath': 'mac',95 },96 'views': {97 'filepath': 'views',98 },99 },100 'WATCHLISTS': {101 'mac': %s,102 'views': %s,103 },104 } """ % (watchers, watchers)105 watchlists.Watchlists._HasWatchlistsFile.return_value = True106 watchlists.Watchlists._ContentsOfWatchlistsFile.return_value = contents107 wl = watchlists.Watchlists('/​a/​path')108 self.assertEqual(wl.GetWatchersForPaths(['file_views_mac']), watchers)109 def testWinPathWatchers(self):110 """Test watchers for a windows path (containing backward slashes)."""111 watchers = ['abc@def.com', 'x1@xyz.org']112 contents = \113 """{114 'WATCHLIST_DEFINITIONS': {115 'browser': {116 'filepath': 'chrome/​browser/​.*',117 },118 },119 'WATCHLISTS': {120 'browser': %s,121 },122 } """ % watchers123 saved_sep = watchlists.os.sep124 watchlists.os.sep = '\\' # to pose as win32125 watchlists.Watchlists._HasWatchlistsFile.return_value = True126 watchlists.Watchlists._ContentsOfWatchlistsFile.return_value = contents127 wl = watchlists.Watchlists(r'a\path')128 returned_watchers = wl.GetWatchersForPaths(129 [r'chrome\browser\renderer_host\render_widget_host.h'])130 watchlists.os.sep = saved_sep # revert back os.sep before asserts131 self.assertEqual(returned_watchers, watchers)132if __name__ == '__main__':133 import unittest...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

Testing Modern Applications With Playwright ????

Web applications continue to evolve at an unbelievable pace, and the architecture surrounding web apps get more complicated all of the time. With the growth in complexity of the web application and the development process, web application testing also needs to keep pace with the ever-changing demands.

Joomla Testing Guide: How To Test Joomla Websites

Before we discuss the Joomla testing, let us understand the fundamentals of Joomla and how this content management system allows you to create and maintain web-based applications or websites without having to write and implement complex coding requirements.

Test Optimization for Continuous Integration

“Test frequently and early.” If you’ve been following my testing agenda, you’re probably sick of hearing me repeat that. However, it is making sense that if your tests detect an issue soon after it occurs, it will be easier to resolve. This is one of the guiding concepts that makes continuous integration such an effective method. I’ve encountered several teams who have a lot of automated tests but don’t use them as part of a continuous integration approach. There are frequently various reasons why the team believes these tests cannot be used with continuous integration. Perhaps the tests take too long to run, or they are not dependable enough to provide correct results on their own, necessitating human interpretation.

7 Skills of a Top Automation Tester in 2021

With new-age project development methodologies like Agile and DevOps slowly replacing the old-age waterfall model, the demand for testing is increasing in the industry. Testers are now working together with the developers and automation testing is vastly replacing manual testing in many ways. If you are new to the domain of automation testing, the organization that just hired you, will expect you to be fast, think out of the box, and able to detect bugs or deliver solutions which no one thought of. But with just basic knowledge of testing, how can you be that successful test automation engineer who is different from their predecessors? What are the skills to become a successful automation tester in 2019? Let’s find out.

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 uiautomator 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