Best Python code snippet using selene_python
Camera.py
Source: Camera.py
...13 self.lpfx = '%s:%s' % (self.address,self.name)14 def start(self):15 LOGGER.debug(f'{self.lpfx} Starting...')16 self.update_status(self.cam)17 self.set_driver('ALARM',0)18 for cat in DETECTED_OBJECT_MAP:19 node = self.controller.addNode(DetectedObject(self.controller, self, cat))20 # Keep track of which node handles which detected object type.21 for otype in DETECTED_OBJECT_MAP[cat]:22 self.detected_obj_by_type[otype] = node23 LOGGER.debug(f'{self.lpfx} Done...')24 self.ready = True25 def update_status(self,cam):26 """27 Given a cam dict from the Camcect API update all our drivers28 """29 LOGGER.debug(f"{self.lpfx}: disabled={cam['disabled']} is_alert_disabled={cam['is_alert_disabled']} is_streaming={cam['is_streaming']}")30 self.set_driver('ST',0 if cam['disabled'] else 1)31 self.set_driver('MODE',0 if cam['is_alert_disabled'] else 1)32 self.set_driver('GPV', 1 if cam['is_streaming'] else 0)33 def callback(self,event):34 # {'type': 'alert', 'desc': 'Out Front Door just saw a person.', 'url': 'https://home.camect.com/home/...', 35 # 'cam_id': '96f69defdef1d0b6602a', 'cam_name': 'Out Front Door', 'detected_obj': ['person']}36 LOGGER.debug(f"{self.lpfx} type={event['type']}")37 if event['type'] == 'alert':38 if 'detected_obj' in event:39 self.detected_obj(event['detected_obj'])40 else:41 LOGGER.error(f"Unknown alert, no detected_obj in {event}")42 def detected_obj(self,object_list):43 LOGGER.debug(f"{self.lpfx} {object_list}")44 # Clear last detected objects45 # TODO: Would be better to timout and clear these during a short poll, but allow for user specified timeout?46 for cat in DETECTED_OBJECT_MAP:47 for otype in DETECTED_OBJECT_MAP[cat]:48 if otype in self.detected_obj_by_type:49 self.detected_obj_by_type[otype].clear()50 else:51 LOGGER.error(f"Internal error, no {otype} in dectected_obj_by_type dict?")52 # And set the current ones53 for obj in object_list:54 if obj in self.detected_obj_by_type:55 LOGGER.debug(f"{self.lpfx} {obj}")56 self.set_driver('ALARM',1)57 #self.set_driver('ALARM',DETECTED_OBJECT_MAP['obj'])58 self.detected_obj_by_type[obj].turn_on(obj)59 else:60 LOGGER.error(f"Unsupported detected object '{obj}'")61 def cmd_alert_on(self, command):62 LOGGER.info("")63 st = self.host.enable_alert(self.cam['id'])64 self.set_driver('MODE', 1)65 def cmd_alert_off(self, command):66 LOGGER.info("")67 st = self.host.disable_alert(self.cam['id'])68 self.set_driver('MODE', 0)69 def cmd_enable_on(self, command):70 #self.controller.enable_alert(self.cam['id'])71 #self.set_driver('GV0', 1)72 pass73 def cmd_enable_off(self, command):74 #self.controller.disable_alert(self.cam['id'])75 #self.set_driver('GV0', 0)76 pass77 def query(self,command=None):78 self.reportDrivers()79 hint = [1,2,3,4]80 drivers = [81 {'driver': 'ST', 'value': 0, 'uom': 2}, # Enabled82 {'driver': 'ALARM', 'value': 0, 'uom': 2}, # Detected83 {'driver': 'MODE', 'value': 0, 'uom': 2}, # Alerting84 {'driver': 'GPV', 'value': 0, 'uom': 2}, # Streaming85 {'driver': 'GV0', 'value': 0, 'uom': 2}, # 86 {'driver': 'GV1', 'value': 0, 'uom': 2}, # 87 {'driver': 'GV2', 'value': 0, 'uom': 2}, # 88 {'driver': 'GV3', 'value': 0, 'uom': 2}, # 89 {'driver': 'GV4', 'value': 0, 'uom': 2}, # ...
DetectedObject.py
Source: DetectedObject.py
...27 self.dname_to_driver[obj_name] = dv2829 def start(self):30 LOGGER.debug(f'{self.lpfx}')31 self.set_driver('ST',0)32 for dn in self.dname_to_driver:33 self.set_driver(self.dname_to_driver[dn], 0)3435 def shortPoll(self):36 pass3738 def longPoll(self):39 pass4041 def clear(self):42 if int(self.get_driver('ST')) == 1:43 LOGGER.debug(f'{self.lpfx}')44 self.reportCmd("DOF",2)45 for obj in self.dname_to_driver:46 self.set_driver(self.dname_to_driver[obj], 0)4748 # This is called by parent when object is detected49 def turn_on(self,obj):50 LOGGER.debug(f"{self.lpfx}")51 self.reportCmd("DON",2)52 self.set_driver(self.dname_to_driver[obj],1)5354 # This is called by parent when object is no longer detected55 def turn_off(self,obj):56 LOGGER.debug(f"{self.lpfx}")57 self.reportCmd("DOF",2)58 self.set_driver(self.dname_to_driver[obj],0)5960 def cmd_on(self, command=None):61 LOGGER.debug(f"{self.lpfx} command={command} ST={self.get_driver('ST')}")62 self.set_driver('ST', 1)6364 def cmd_off(self, command=None):65 LOGGER.debug(f"{self.lpfx} command={command} ST={self.get_driver('ST')}")66 self.set_driver('ST', 1)6768 def query(self,command=None):69 LOGGER.debug(f'{self.lpfx}')70 self.reportDrivers()7172 hint = [1,2,3,4]73 commands = {74 'DON': cmd_on,75 'DOF': cmd_off,
...
main.py
Source: main.py
...3import urllib.request4from selenium.webdriver import Chrome, ChromeOptions5from selenium.webdriver import Firefox6from selenium.webdriver.firefox.options import Options7def set_driver(driver_path, headless_flg):8 if "chrome" in driver_path:9 options = ChromeOptions()10 else:11 options = Options()12 # ãããã¬ã¹ã¢ã¼ãï¼ç»é¢é表示ã¢ã¼ãï¼ãè¨å®13 if headless_flg == True:14 options.add_argument('--headless')15 # èµ·åãªãã·ã§ã³ã®è¨å®16 options.add_argument(17 '--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36')18 # options.add_argument('log-level=3')19 options.add_argument('--ignore-certificate-errors')20 options.add_argument('--ignore-ssl-errors')21 options.add_argument('--incognito') # ã·ã¼ã¯ã¬ããã¢ã¼ãã®è¨å®ãä»ä¸22 # Chromeã®WebDriverãªãã¸ã§ã¯ããä½æããã23 if "chrome" in driver_path:24 return Chrome(executable_path=os.getcwd() + "/" + driver_path,options=options)25 else:26 return Firefox(executable_path=os.getcwd() + "/" + driver_path,options=options)27def download_pics_mercari():28 # driverãèµ·å29 if os.name == 'nt': #Windows30 driver = set_driver("chromedriver.exe", False)31 elif os.name == 'posix': #Mac32 driver = set_driver("chromedriver", False)33 driver.get("https://jp.mercari.com/item/m60273403967")34 time.sleep(10)35 36 37 # ãã¿ã³ãã¯ãªãã¯38 driver.find_element_by_xpath('/html/body/mer-information-popup/div[2]/mer-button/button').click()39 time.sleep(5)40 elements = driver.find_elements_by_tag_name('mer-item-thumbnail')41 for element in elements:42 pic_url = element.get_attribute('src')43 urllib.request.urlretrieve(pic_url, 'logo.png')44 45if __name__ == "__main__":46 download_pics_mercari()...
Check out the latest blogs from LambdaTest on this topic:
There are times when developers get stuck with a problem that has to do with version changes. Trying to run the code or test without upgrading the package can result in unexpected errors.
Automating testing is a crucial step in the development pipeline of a software product. In an agile development environment, where there is continuous development, deployment, and maintenance of software products, automation testing ensures that the end software products delivered are error-free.
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.
“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.
Hey LambdaTesters! We’ve got something special for you this week. ????
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!