How to use check_image method in tempest

Best Python code snippet using tempest_python

unCaptcha.py

Source:unCaptcha.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-23import random4import re5import time6import urlparse, urllib,urllib2,cookielib78from base64 import b64encode9import xbmc10import xbmcgui,xbmcaddon,os11__scriptID__ = 'plugin.video.live.RSIPTV'12__addon__ = xbmcaddon.Addon(__scriptID__)1314class cInputWindow(xbmcgui.WindowDialog):15 def __init__(self, *args, **kwargs):16 17 bg_image = os.path.join( __addon__.getAddonInfo('path'), 'Images/' ) + "background.png"18 check_image = os.path.join( __addon__.getAddonInfo('path'), 'Images/' ) + "trans_checked.png"19 uncheck_image = os.path.join( __addon__.getAddonInfo('path'), 'Images/' ) + "trans_unchecked1.png"20 self.ctrlBackgound = xbmcgui.ControlImage(21 0,0, 22 1280, 720, 23 bg_image24 )25 self.cancelled=False26 self.addControl (self.ctrlBackgound)27 self.msg = kwargs.get('msg')+'\nNormally there are 3-4 selections and 2 rounds of pictures'28 self.round=kwargs.get('round')29 self.strActionInfo = xbmcgui.ControlLabel(335, 120, 700, 300, self.msg, 'font13', '0xFFFF00FF')30 self.addControl(self.strActionInfo)31 32 self.strActionInfo = xbmcgui.ControlLabel(335, 20, 724, 400, 'Captcha round %s'%(str(self.round)), 'font40', '0xFFFF00FF')33 self.addControl(self.strActionInfo)34 35 self.cptloc = kwargs.get('captcha')36 #self.img = xbmcgui.ControlImage(335,200,624,400,self.cptloc)37 imgw=40038 imgh=30039 imgX=33540 imgY=20041 pw=imgw/342 ph=imgh/343 self.img = xbmcgui.ControlImage(imgX,imgY,imgw,imgh,self.cptloc)44 self.addControl(self.img)45 46 self.chk=[0]*947 self.chkbutton=[0]*948 self.chkstate=[False]*949 50 #self.chk[0] = xbmcgui.ControlCheckMark(335,200,200,200,'select',checkWidth=30, checkHeight=30)51 52 self.chk[0]= xbmcgui.ControlImage(imgX,imgY, pw, ph,check_image)# '', font='font1',focusTexture=check_image ,noFocusTexture=uncheck_image,checkWidth=220,checkHeight=150)53 self.chk[1]= xbmcgui.ControlImage(imgX+pw,imgY, pw, ph,check_image)# '', font='font14',focusTexture=check_image ,noFocusTexture=uncheck_image,checkWidth=220,checkHeight=150)54 self.chk[2]= xbmcgui.ControlImage(imgX+pw+pw,imgY, pw, ph,check_image)# '', font='font14',focusTexture=check_image ,noFocusTexture=uncheck_image,checkWidth=220,checkHeight=150)55 56 self.chk[3]= xbmcgui.ControlImage(imgX,imgY+ph, pw, ph,check_image)# '', font='font14',focusTexture=check_image ,noFocusTexture=uncheck_image,checkWidth=220,checkHeight=150)57 self.chk[4]= xbmcgui.ControlImage(imgX+pw,imgY+ph, pw, ph,check_image)# '', font='font14',focusTexture=check_image ,noFocusTexture=uncheck_image,checkWidth=220,checkHeight=150)58 self.chk[5]= xbmcgui.ControlImage(imgX+pw+pw,imgY+ph, pw, ph,check_image)# '', font='font14',focusTexture=check_image ,noFocusTexture=uncheck_image,checkWidth=220,checkHeight=150)59 60 61 self.chk[6]= xbmcgui.ControlImage(imgX,imgY+ph+ph, pw, ph,check_image)#, '', font='font14',focusTexture=check_image ,noFocusTexture=uncheck_image,checkWidth=220,checkHeight=150)62 self.chk[7]= xbmcgui.ControlImage(imgX+pw,imgY+ph+ph, pw, ph,check_image)# '', font='font14',focusTexture=check_image ,noFocusTexture=uncheck_image,checkWidth=220,checkHeight=150)63 self.chk[8]= xbmcgui.ControlImage(imgX+pw+pw,imgY+ph+ph, pw, ph,check_image)# '', font='font14',focusTexture=check_image ,noFocusTexture=uncheck_image,checkWidth=220,checkHeight=150)64 65 66 self.chkbutton[0]= xbmcgui.ControlButton(imgX,imgY, pw, ph, '1', font='font1');#,focusTexture=check_image ,noFocusTexture=uncheck_image);#,checkWidth=220,checkHeight=150)67 self.chkbutton[1]= xbmcgui.ControlButton(imgX+pw,imgY, pw, ph, '2', font='font1');#,focusTexture=check_image ,noFocusTexture=uncheck_image);#,checkWidth=220,checkHeight=150)68 self.chkbutton[2]= xbmcgui.ControlButton(imgX+pw+pw,imgY, pw, ph, '3', font='font1');#,focusTexture=check_image ,noFocusTexture=uncheck_image);#,checkWidth=220,checkHeight=150)69 70 self.chkbutton[3]= xbmcgui.ControlButton(imgX,imgY+ph, pw, ph, '4', font='font1');#,focusTexture=check_image ,noFocusTexture=uncheck_image);#,checkWidth=220,checkHeight=150)71 self.chkbutton[4]= xbmcgui.ControlButton(imgX+pw,imgY+ph, pw, ph, '5', font='font1');#,focusTexture=check_image ,noFocusTexture=uncheck_image);#,checkWidth=220,checkHeight=150)72 self.chkbutton[5]= xbmcgui.ControlButton(imgX+pw+pw,imgY+ph, pw, ph, '6', font='font1');#,focusTexture=check_image ,noFocusTexture=uncheck_image);#,checkWidth=220,checkHeight=150)73 74 75 self.chkbutton[6]= xbmcgui.ControlButton(imgX,imgY+ph+ph, pw, ph, '7', font='font1');#,focusTexture=check_image ,noFocusTexture=uncheck_image);#,checkWidth=220,checkHeight=150)76 self.chkbutton[7]= xbmcgui.ControlButton(imgX+pw,imgY+ph+ph, pw, ph, '8', font='font1');#,focusTexture=check_image ,noFocusTexture=uncheck_image);#,checkWidth=220,checkHeight=150)77 self.chkbutton[8]= xbmcgui.ControlButton(imgX+pw+pw,imgY+ph+ph, pw, ph, '9', font='font1');#,focusTexture=check_image ,noFocusTexture=uncheck_image);#,checkWidth=220,checkHeight=150)78 79 8081 82 for obj in self.chk:83 self.addControl(obj )84 obj.setVisible(False)85 for obj in self.chkbutton:86 self.addControl(obj )87 88 89 90 #self.chk[0].setSelected(False)91 92 self.cancelbutton = xbmcgui.ControlButton(imgX+(imgw/2)-110,imgY+imgh+10,100,40,'Cancel',alignment=2)93 self.okbutton = xbmcgui.ControlButton(imgX+(imgw/2)+10,imgY+imgh+10,100,40,'OK',alignment=2)94 self.addControl(self.okbutton)95 self.addControl(self.cancelbutton)9697 self.chkbutton[6].controlDown(self.cancelbutton); self.chkbutton[6].controlUp(self.chkbutton[3])98 self.chkbutton[7].controlDown(self.cancelbutton); self.chkbutton[7].controlUp(self.chkbutton[4])99 self.chkbutton[8].controlDown(self.okbutton); self.chkbutton[8].controlUp(self.chkbutton[5])100 101 102 self.chkbutton[6].controlLeft(self.chkbutton[8]);self.chkbutton[6].controlRight(self.chkbutton[7]);103 self.chkbutton[7].controlLeft(self.chkbutton[6]);self.chkbutton[7].controlRight(self.chkbutton[8]);104 self.chkbutton[8].controlLeft(self.chkbutton[7]);self.chkbutton[8].controlRight(self.chkbutton[6]);105 106 self.chkbutton[3].controlDown(self.chkbutton[6]); self.chkbutton[3].controlUp(self.chkbutton[0])107 self.chkbutton[4].controlDown(self.chkbutton[7]); self.chkbutton[4].controlUp(self.chkbutton[1])108 self.chkbutton[5].controlDown(self.chkbutton[8]); self.chkbutton[5].controlUp(self.chkbutton[2])109 110 self.chkbutton[3].controlLeft(self.chkbutton[5]);self.chkbutton[3].controlRight(self.chkbutton[4]);111 self.chkbutton[4].controlLeft(self.chkbutton[3]);self.chkbutton[4].controlRight(self.chkbutton[5]);112 self.chkbutton[5].controlLeft(self.chkbutton[4]);self.chkbutton[5].controlRight(self.chkbutton[3]);113114 self.chkbutton[0].controlDown(self.chkbutton[3]); self.chkbutton[0].controlUp(self.cancelbutton)115 self.chkbutton[1].controlDown(self.chkbutton[4]); self.chkbutton[1].controlUp(self.cancelbutton)116 self.chkbutton[2].controlDown(self.chkbutton[5]); self.chkbutton[2].controlUp(self.okbutton)117 118 self.chkbutton[0].controlLeft(self.chkbutton[2]);self.chkbutton[0].controlRight(self.chkbutton[1]);119 self.chkbutton[1].controlLeft(self.chkbutton[0]);self.chkbutton[1].controlRight(self.chkbutton[2]);120 self.chkbutton[2].controlLeft(self.chkbutton[1]);self.chkbutton[2].controlRight(self.chkbutton[0]);121 122 self.cancelled=False123 self.setFocus(self.okbutton)124 self.okbutton.controlLeft(self.cancelbutton);self.okbutton.controlRight(self.cancelbutton); 125 self.cancelbutton.controlLeft(self.okbutton); self.cancelbutton.controlRight(self.okbutton);126 self.okbutton.controlDown(self.chkbutton[2]);self.okbutton.controlUp(self.chkbutton[8]); 127 self.cancelbutton.controlDown(self.chkbutton[0]); self.cancelbutton.controlUp(self.chkbutton[6]); 128 #self.kbd = xbmc.Keyboard()129130 def get(self):131 self.doModal()132 #self.kbd.doModal()133 #if (self.kbd.isConfirmed()):134 # text = self.kbd.getText()135 # self.close()136 # return text137 #xbmc.sleep(5000)138 self.close()139 if not self.cancelled: 140 retval=""141 for objn in range(9):142 if self.chkstate[objn]:#self.chk[objn].getSelected() :143 retval+=("" if retval=="" else ",")+str(objn)144 return retval145 146 else:147 return ""148# def onControl(self,control):149# if control == self.okbutton:150# self.close()151# elif control == self.cancelbutton:152# self.cancelled=True153# self.close()154 def anythingChecked(self):155 for obj in self.chkstate:156 if obj:#obj.getSelected():157 return True158 return False159 160 161 def onControl(self,control):162 if control==self.okbutton: 163 if self.anythingChecked():164 self.close()165 elif control== self.cancelbutton:166 self.cancelled=True167 self.close()168 try:169 #print control170 if 'xbmcgui.ControlButton' in repr(type(control)):171 index=control.getLabel()172 #print 'index',index173 if index.isnumeric():174 #print 'index2',index175 #self.chk[int(index)-1].setSelected(not self.chk[int(index)-1].getSelected())176 self.chkstate[int(index)-1]= not self.chkstate[int(index)-1]177 self.chk[int(index)-1].setVisible(self.chkstate[int(index)-1])178 #print 'ddone'179 180 except: pass181# def onClick(self, controlId):182# print 'CLICKED',controlId183 def onAction(self, action):184 if action == 10:#ACTION_PREVIOUS_MENU:185 self.cancelled=True186 self.close()187 188 189def getUrl(url, cookieJar=None,post=None, timeout=20, headers=None, noredir=False):190191 cookie_handler = urllib2.HTTPCookieProcessor(cookieJar)192193 if noredir:194 opener = urllib2.build_opener(NoRedirection,cookie_handler, urllib2.HTTPBasicAuthHandler(), urllib2.HTTPHandler())195 else:196 opener = urllib2.build_opener(cookie_handler, urllib2.HTTPBasicAuthHandler(), urllib2.HTTPHandler())197 #opener = urllib2.install_opener(opener)198 req = urllib2.Request(url)199 req.add_header('User-Agent','Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36')200 if headers:201 for h,hv in headers:202 req.add_header(h,hv)203204 response = opener.open(req,post,timeout=timeout)205 link=response.read()206 response.close()207 return link;208209class UnCaptchaReCaptcha:210 def processCaptcha(self, key,lang):211 212 headers=[("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0"),213 ("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"),214 ("Referer", "https://www.google.com/recaptcha/api2/demo"),215 ("Accept-Language", lang)];216217 html=getUrl("http://www.google.com/recaptcha/api/fallback?k=" + key,headers=headers);218 token=""219 round=0220 while True:221 payload = re.findall("\"(/recaptcha/api2/payload[^\"]+)",html);222 round+=1223 message =re.findall("<label .*?class=\"fbc-imageselect-message-text\">(.*?)</label>",html);224 if len(message)==0:225 message =re.findall("<div .*?class=\"fbc-imageselect-message-error\">(.*?)</div>",html)226 if len(message)==0:227 token = re.findall("\"this\\.select\\(\\)\">(.*?)</textarea>",html)[0];228 if not token=="":229 line1 = "Captcha Sucessfull"230 xbmc.executebuiltin('Notification(%s, %s, %d, %s)'%('LSPro',line1, 3000, None))231 else:232 line1 = "Captcha failed"233 xbmc.executebuiltin('Notification(%s, %s, %d, %s)'%('LSPro',line1, 3000, None))234 break235 else:236 message=message[0]237 payload=payload[0]238239240 imgurl=re.findall("name=\"c\"\\s+value=\\s*\"([^\"]+)",html)[0]241242 headers=[("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0"),243 ("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"),244 ("Referer", "http://www.google.com/recaptcha/api/fallback?k=" + key),245 ("Accept-Language", lang)];246 247 cval=re.findall('name="c" value="(.*?)"',html)[0]248 captcha_imgurl = "https://www.google.com"+payload.replace('&amp;','&')249 250 #print message251 message=message.replace('<strong>','')252 message=message.replace('</strong>','')253 #captcha_response=raw_input('-->')254 255 oSolver = cInputWindow(captcha = captcha_imgurl,msg = message,round=round)256 captcha_response = oSolver.get()257 #print 'captcha_response',captcha_response258 if captcha_response=="":259 break260 responses=""261 for rr in captcha_response.split(','):262 responses += "&response=" + rr;263 264 265 html = getUrl("http://www.google.com/recaptcha/api/fallback?k="+key 266 ,post=urllib.urlencode({'c' : cval,})+responses,headers=headers)#.decode('unicode-escape')267 #print html268 return token269270271def performCaptcha(sitename,cj,returnpage=True,captcharegex='data-sitekey="(.*?)"',lang="en",headers=None):272273274 sitepage=getUrl(sitename,cookieJar=cj,headers=headers)275 sitekey=re.findall(captcharegex,sitepage)276 token=""277 if len(sitekey)>=1:278 c=UnCaptchaReCaptcha()279 token=c.processCaptcha(sitekey[0],lang)280 if returnpage:281 if headers==None:282 headers=[("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0"),283 ("Referer", sitename)];284 else:285 headers+=[("Referer", sitename)]286 sitepage=getUrl(sitename,cookieJar=cj,post=urllib.urlencode({"g-recaptcha-response":token}),headers=headers)287 288 if returnpage:289 return sitepage290 else:291 return token292293#cookieJar = cookielib.LWPCookieJar()294#performCaptcha("http://www.livetv.tn/",cookieJar);295 ...

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