Best Python code snippet using pyatom_python
viera.py
Source:viera.py
1import urllib.request2import xml.etree.ElementTree as ET3class Viera(object):4 def __init__(self, hostname, control_url, service_type):5 self.hostname = hostname6 self.control_url = control_url7 self.service_type = service_type8 self.sendkey_action = Action('X_SendKey', ('X_KeyEvent',))9 def _sendkey(self, slug):10 req = self.sendkey_action.to_soap_request(11 self.control_url,12 self.hostname,13 self.service_type,14 (slug,),15 )16 urllib.request.urlopen(req).read()17 def __unicode__(self):18 return u'<Hostname:%s ControlURL:%s ServiceType:%s>' % (19 self.hostname,20 self.control_url,21 self.service_type,22 )23 def netflix(self):24 self._sendkey('NRC_NETFLIX-ONOFF')25 def vol_up(self):26 self._sendkey('NRC_VOLUP-ONOFF')27 def vol_down(self):28 self._sendkey('NRC_VOLDOWN-ONOFF')29 def mute(self):30 self._sendkey('NRC_MUTE-ONOFF')31 def pause(self):32 self._sendkey('NRC_PAUSE-ONOFF')33 def num(self, number):34 for digit in str(number):35 self._sendkey('NRC_D%s-ONOFF' % digit)36 def power(self):37 self._sendkey('NRC_POWER-ONOFF')38 def toggle_3D(self):39 self._sendkey('NRC_3D-ONOFF')40 def toggle_SDCard(self):41 self._sendkey('NRC_SD_CARD-ONOFF')42 def red(self):43 self._sendkey('NRC_RED-ONOFF')44 def green(self):45 self._sendkey('NRC_GREEN-ONOFF')46 def yellow(self):47 self._sendkey('NRC_YELLOW-ONOFF')48 def blue(self):49 self._sendkey('NRC_BLUE-ONOFF')50 def vtools(self):51 self._sendkey('NRC_VTOOLS-ONOFF')52 def cancel(self):53 self._sendkey('NRC_CANCEL-ONOFF')54 def option(self):55 self._sendkey('NRC_SUBMENU-ONOFF')56 def Return(self):57 self.sendkey('NRC_RETURN-ONOFF')58 def enter(self):59 self._sendkey('NRC_ENTER-ONOFF')60 def right(self):61 self._sendkey('NRC_RIGHT-ONOFF')62 def left(self):63 self._sendkey('NRC_LEFT-ONOFF')64 def up(self):65 self._sendkey('NRC_UP-ONOFF')66 def down(self):67 self._sendkey('NRC_DOWN-ONOFF')68 def display(self):69 self._sendkey('NRC_DISP_MODE-ONOFF')70 def menu(self):71 self._sendkey('NRC_MENU-ONOFF')72 def connect(self):73 self._sendkey('NRC_INTERNET-ONOFF')74 def link(self):75 self._sendkey('NRC_VIERA_LINK-ONOFF')76 def guide(self):77 self._sendkey('NRC_EPG-ONOFF')78 def text(self):79 self._sendkey('NRC_TEXT-ONOFF')80 def subtitles(self):81 self._sendkey('NRC_STTL-ONOFF')82 def info(self):83 self._sendkey('NRC_INFO-ONOFF')84 def index(self):85 self._sendkey('NRC_INDEX-ONOFF')86 def hold(self):87 self._sendkey('NRC_HOLD-ONOFF')88class Action(object):89 def __init__(self, name, arguments):90 self.name = name91 self.arguments = arguments92 def to_soap_request(self, url, hostname, service_type, values):93 assert len(values) == len(self.arguments)94 params = ''.join(['<%s>%s</%s>' % (arg, value, arg) for arg, value in zip(self.arguments, values)])95 soap_body = (96 '<?xml version="1.0"?>'97 '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">'98 '<SOAP-ENV:Body>'99 '<m:%(method_name)s xmlns:m="%(service_type)s">'100 '%(params)s'101 '</m:%(method_name)s>'102 '</SOAP-ENV:Body>'103 '</SOAP-ENV:Envelope>'104 ) % {105 'method_name': self.name,106 'service_type': service_type,107 'params': params,108 }109 headers = {110 'Host': hostname,111 'Content-Length': len(soap_body),112 'Content-Type': 'text/xml',113 'SOAPAction': '"%s#%s"' % (service_type, self.name),114 }115 req = urllib.request.Request(url, soap_body.encode(), headers)...
loginBO.py
Source:loginBO.py
...23 24 25 def run(self):26# self.locator.getLocator(xpath/css locator,po object) return PO object27# ._sendKey("admin")28 self.locator.getLocator(LoginPage.getInputField("id=id_username"),self.pageobject)._sendKey("admin")29 time.sleep(1)30 self.locator.getLocator(LoginPage.getInputField("id=id_password"),self.pageobject)._sendKey("netis")31 time.sleep(1)32 self.locator.getLocator(LoginPage.getInputField("css=button.btn.btn-primary"),self.pageobject)._click()33 time.sleep(3)34 print self.pageobject.driver.title35# self.assertTrue(self.pageobject.driver.title, u"ä¸å¤®ä»ªè¡¨å° - NPM")36 assert u"Central Dashboard - NPM" in self.pageobject.driver.title, u"æ é¢éªè¯é误ï¼expect is Central Dashboard - NPMï¼ but actual is %s" % self.pageobject.driver.title 37 38 39 ...
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!!