Example #1
0
def get_oracle(url):
  source = util.get_source(url)
  html = lxml.html.document_fromstring(source)
  html.make_links_absolute(url, resolve_base_href=True)
  util.save_file(lxml.html.tostring(html), 'oracle.html')
  util.screenshot('oracle.html', 'oracle.png')
  return html
Example #2
0
 def trial_done(self):
     self.trial_complete = True
     t = get_time()
     self.search_time = t - self.start_time
     self.logger.write(system_time=t, mode=director.settings['mode'], trial=self.current_trial,
                       event_source="TASK", event_type=self.states[self.state], state=self.states[self.state],
                       event_id="END", **self.log_extra)
     self.state = self.STATE_RESULTS
     self.logger.write(system_time=t, mode=director.settings['mode'], trial=self.current_trial,
                       event_source="TASK", event_type=self.states[self.state], state=self.states[self.state],
                       study_time=self.study_time, search_time=self.search_time, **self.log_extra)
     
     tmp = self.logger.file.getvalue()
     data = tarfile.TarInfo("%s/trial-%02d.txt" % (director.settings['filebase'], self.current_trial))
     data.size = len(tmp)
     self.tarfile.addfile(data, StringIO(tmp))
     
     tmp = StringIO()
     screenshot().save(tmp, "png")
     data = tarfile.TarInfo("%s/trial-%02d.png" % (director.settings['filebase'], self.current_trial))
     data.size = len(tmp.getvalue())
     tmp.seek(0)
     self.tarfile.addfile(data, tmp)
     
     self.logger.close()
     if director.settings['eyetracker'] and self.client:
         self.client.removeDispatcher(self.d)
         self.client.stopFixationProcessing()
     
     if director.settings['player'] == 'ACT-R' and director.settings['mode'] != 'Experiment':
         self.client_actr.trigger_event(":trial-complete")
     else:
         self.next_trial()
Example #3
0
def seed_html_fault(html, elements, prop, value):
    while elements:
        e = random.choice(elements)
        elements.remove(e)
        original_style = None
        if prop in e.attrib:
            original_value = e.attrib[prop]
            e.attrib[prop] = value
            util.save_file(lxml.html.tostring(html, doctype=html.doctype),
                           'test.html')
            util.screenshot('test.html', 'test.png')
            e.attrib[prop] = original_value
        else:
            e.attrib[prop] = value
            util.save_file(lxml.html.tostring(html, doctype=html.doctype),
                           'test.html')
            util.screenshot('test.html', 'test.png')
            del e.attrib[prop]
        if not filecmp.cmp('oracle.png', 'test.png'):
            xpath = get_xpath(e)
            default_value = util.get_default_value('oracle.html',
                                                   xpath,
                                                   prop,
                                                   css=False)
            return (xpath, default_value, value)
            break
    return (None, None, None)
Example #4
0
def change_property(htmlfile, xpath, prop, value):
    html = lxml.html.parse(htmlfile)
    elements = html.xpath(xpath)
    for e in elements:
        if "style" in e.attrib:
            original_style = e.attrib["style"]
            e.attrib["style"] += ";{0}:{1};".format(prop, value)
        else:
            e.attrib["style"] = "{0}:{1};".format(prop, value)
        util.save_file(lxml.html.tostring(html), "temp.html")
        util.screenshot("temp.html", "temp.png")
Example #5
0
def change_property(htmlfile, xpath, prop, value):
    html = lxml.html.parse(htmlfile)
    elements = html.xpath(xpath)
    for e in elements:
        if 'style' in e.attrib:
            original_style = e.attrib['style']
            e.attrib['style'] += ';{0}:{1};'.format(prop, value)
        else:
            e.attrib['style'] = '{0}:{1};'.format(prop, value)
        util.save_file(lxml.html.tostring(html), 'temp.html')
        util.screenshot('temp.html', 'temp.png')
Example #6
0
    def on_key_press(self, symbol, modifiers):
        if symbol == key.F and (modifiers & key.MOD_ACCEL):
            director.window.set_fullscreen(not director.window.fullscreen)
            return True

        elif symbol == key.X and (modifiers & key.MOD_ACCEL):
            director.show_FPS = not director.show_FPS
            return True

        elif symbol == key.S and (modifiers & key.MOD_ACCEL):
            screenshot().save('screenshot-%d.png' % (int(time.time())))
            return True
Example #7
0
File: gen.py Project: jineli/websee
def process(url, ads_xpath):
  test_dir = urlparse.urlparse(url).hostname
  if os.path.isdir(test_dir):
    shutil.rmtree(test_dir)
  os.mkdir(test_dir)
  if os.path.isfile(test_dir + 'description.txt'):
    os.remove(test_dir + 'description.txt')
  oracle_html = get_oracle(url)
  for xpath in ads_xpath:
    oracle_html = hide_advertisement(oracle_html, xpath)
  util.save_file(lxml.html.tostring(oracle_html, doctype=oracle_html.doctype), 'oracle.html')
  util.screenshot('oracle.html', 'oracle.png')
  total = 0
  total = process_css(test_dir, oracle_html, total)
  total = process_html(test_dir, oracle_html, total)
Example #8
0
def process(url, ads_xpath):
    test_dir = urlparse.urlparse(url).hostname
    if os.path.isdir(test_dir):
        shutil.rmtree(test_dir)
    os.mkdir(test_dir)
    if os.path.isfile(test_dir + 'description.txt'):
        os.remove(test_dir + 'description.txt')
    oracle_html = get_oracle(url)
    for xpath in ads_xpath:
        oracle_html = hide_advertisement(oracle_html, xpath)
    util.save_file(
        lxml.html.tostring(oracle_html, doctype=oracle_html.doctype),
        'oracle.html')
    util.screenshot('oracle.html', 'oracle.png')
    total = 0
    total = process_css(test_dir, oracle_html, total)
    total = process_html(test_dir, oracle_html, total)
Example #9
0
 def getInfo(self):
     screen = screenshot(lx, ly, rx, ry)
     screenGray = cv2.cvtColor(screen, cv2.COLOR_BGR2GRAY)
     self.playerPos = findPlayer(screenGray, playerTemplate)
     self.playerX, self.playerY = self.playerPos
     mobPos = findMob(screenGray, mobTemplate)
     self.closestMob = findClosest(self.playerPos, mobPos)
     self.dist = (self.closestMob[0] - self.playerX)
     self.direction = RIGHT if self.dist > 0 else LEFT
     cv2.rectangle(screen, (self.playerX - 30, self.playerY - 20), (self.playerX + 30, self.playerY + 50), (0, 0, 255), 5)
     cv2.rectangle(screen, (self.closestMob[0] - 10, self.closestMob[1] + 30), (self.closestMob[0] + 30, self.closestMob[1] + 65), (255, 0, 0), 5)
     cv2.imshow("Game", cv2.resize(screen, (640, 360)))
     cv2.waitKey(1)
Example #10
0
File: gen.py Project: jineli/websee
def seed_css_fault(html, elements, prop, value):
  while elements:
    e = random.choice(elements)
    elements.remove(e)
    original_style = None
    if 'style' in e.attrib:
      original_style = e.attrib['style']
      e.attrib['style'] += ';{0}:{1};'.format(prop, value)
    else:
      e.attrib['style'] = '{0}:{1};'.format(prop, value)
    util.save_file(lxml.html.tostring(html, doctype=html.doctype), 'test.html')
    util.screenshot('test.html', 'test.png')
    if original_style is not None:
      e.attrib['style'] = original_style
    else:
      del e.attrib['style']
    if not filecmp.cmp('oracle.png', 'test.png'):
      xpath = get_xpath(e)
      default_value = util.get_default_value('oracle.html', xpath, prop)
      return (xpath, default_value, value)
      break
  return (None, None, None)
Example #11
0
File: gen.py Project: jineli/websee
def seed_html_fault(html, elements, prop, value):
  while elements:
    e = random.choice(elements)
    elements.remove(e)
    original_style = None
    if prop in e.attrib:
      original_value = e.attrib[prop]
      e.attrib[prop] = value
      util.save_file(lxml.html.tostring(html, doctype=html.doctype), 'test.html')
      util.screenshot('test.html', 'test.png')
      e.attrib[prop] = original_value
    else:
      e.attrib[prop] = value
      util.save_file(lxml.html.tostring(html, doctype=html.doctype), 'test.html')
      util.screenshot('test.html', 'test.png')
      del e.attrib[prop]
    if not filecmp.cmp('oracle.png', 'test.png'):
      xpath = get_xpath(e)
      default_value = util.get_default_value('oracle.html', xpath, prop, 
        css=False)
      return (xpath, default_value, value)
      break
  return (None, None, None)
Example #12
0
def seed_error(html, elements, prop, value):
  while elements:
    e = random.choice(elements)
    elements.remove(e)
    #print 'Trying ', e
    original_style = None
    if 'style' in e.attrib:
      original_style = e.attrib['style']
      e.attrib['style'] += ';{0}:{1};'.format(prop, value)
    else:
      e.attrib['style'] = '{0}:{1};'.format(prop, value)
    util.save_file(lxml.html.tostring(html), 'test.html')
    util.screenshot('test.html', 'test.png')
    if original_style:
      e.attrib['style'] = original_style
    else:
      del e.attrib['style']
    if not filecmp.cmp('oracle.png', 'test.png'):
      xpath = get_xpath(e)
      default_value = util.get_default_value('oracle.html', xpath, prop)
      return (xpath, default_value, value)
      break
  return (None, None, None)
Example #13
0
    def test_search_field(self):
        logger = appLogger.getLogger(__name__)

        try:
            result.setResult('f', 'start')
            driver = self.driver
            wait = WebDriverWait(driver, 20)
            result.setResult('f', 'conn')
            '''
            util.clickElementByIdWithCnt(driver, "com.android.packageinstaller:id/permission_allow_button", 3)
            util.clickElementById(driver, "com.olleh.android.oc2:id/guide_start")
            util.clickElementByXPath(driver, "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout")
            
            '''

            util.clickElementById(
                driver,
                "com.kt.ollehfamilybox:id/btn_setting_permission_confirm")
            util.clickElementByIdWithCnt(
                driver,
                "com.android.packageinstaller:id/permission_allow_button", 2)
            util.clickElementById(driver,
                                  "com.kt.ollehfamilybox:id/next_button")
            util.clickElementById(driver,
                                  "com.kt.ollehfamilybox:id/next_button")
            util.clickElementById(driver,
                                  "com.kt.ollehfamilybox:id/next_button")
            util.clickElementById(driver,
                                  "com.kt.ollehfamilybox:id/begin_button")

            time.sleep(2)
            try:
                el7 = driver.find_element_by_id(
                    "com.kt.ollehfamilybox:id/bt_notice_dialog_not_visible_one_week"
                )
                el7.click()

            except NoSuchElementException:
                print("no notice popup")

            result.setResult('f', 'boot')
            util.clickElementByXPath(
                driver,
                "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.ScrollView/android.widget.LinearLayout/android.widget.LinearLayout[1]/android.widget.HorizontalScrollView/android.widget.LinearLayout/android.widget.FrameLayout[1]/android.widget.LinearLayout/android.widget.Button[1]"
            )
            util.clickElementByXPath(
                driver,
                "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.ScrollView/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.TextView"
            )
            util.clickElementById(driver,
                                  "com.kt.ollehfamilybox:id/tab2_button")

            result.setResult('f', 'login')
            util.sendKeyElementById(
                driver, "com.kt.ollehfamilybox:id/et_id_login_input_id",
                prop.loginId)
            util.sendKeyElementById(
                driver, "com.kt.ollehfamilybox:id/et_id_login_input_pw",
                prop.loginpwd)
            util.clickElementById(driver,
                                  "com.kt.ollehfamilybox:id/bt_id_login")

            util.clickElementByXPath(
                driver,
                "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout[2]/android.widget.ListView/android.widget.LinearLayout[2]"
            )
            util.clickElementByXPath(
                driver,
                "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.Button"
            )
            util.clickElementById(
                driver, "com.kt.ollehfamilybox:id/btn_common_dialog_right")

            time.sleep(10)
            util.screenshot("f.png")

            util.clickElementByXPath(
                driver,
                "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.RelativeLayout"
            )

            result.setResult('f', 'logout')
            util.clickElementById(
                driver, "com.kt.ollehfamilybox:id/iv_navigation_logout")
            util.clickElementById(
                driver, "com.kt.ollehfamilybox:id/btn_common_dialog_right")
            '''




            el1 = driver.find_element_by_id("com.kt.ollehfamilybox:id/btn_setting_permission_confirm")
            el1.click()
            el2 = driver.find_element_by_id("com.android.packageinstaller:id/permission_allow_button")
            el2.click()
            el2.click()
            el3 = driver.find_element_by_id("com.kt.ollehfamilybox:id/next_button")p
            el3.click()
            el4 = driver.find_element_by_id("com.kt.ollehfamilybox:id/next_button")
            el4.click()
            el5 = driver.find_element_by_id("com.kt.ollehfamilybox:id/next_button")
            el5.click()
            el6 = driver.find_element_by_id("com.kt.ollehfamilybox:id/begin_button")
            el6.click()
            
            result.setResult('f', 'boot')
            el7 = driver.find_element_by_xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.ScrollView/android.widget.LinearLayout/android.widget.LinearLayout[1]/android.widget.HorizontalScrollView/android.widget.LinearLayout/android.widget.FrameLayout[1]/android.widget.LinearLayout/android.widget.Button[1]")
            el7.click()
            el8 = driver.find_element_by_xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.ScrollView/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.TextView")
            el8.click()
            el9 = driver.find_element_by_id("com.kt.ollehfamilybox:id/tab2_button")
            el9.click()

            result.setResult('f', 'login')
            el10 = driver.find_element_by_id("com.kt.ollehfamilybox:id/et_id_login_input_id")
            el10.send_keys(prop.loginId)
            el11 = driver.find_element_by_id("com.kt.ollehfamilybox:id/et_id_login_input_pw")
            el11.send_keys(prop.loginpwd)
            el12 = driver.find_element_by_id("com.kt.ollehfamilybox:id/bt_id_login")
            el12.click()
            
            el12_1 = driver.find_element_by_xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout[2]/android.widget.ListView/android.widget.LinearLayout[2]")
            el12_1.click()
            
            #el12_2 = driver.find_element_by_id("com.kt.ollehfamilybox:id/com.kt.ollehfamilybox:id/bt_submit")
            #el12_2.click()

            el12_1 = driver.find_element_by_xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.Button")
            el12_1.click()
            
            el13 = driver.find_element_by_id("com.kt.ollehfamilybox:id/btn_common_dialog_right")
            el13.click()
            
            el14 = driver.find_element_by_xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.RelativeLayout")
            el14.click()
            logger.info('send mail4444')
            
            result.setResult('f', 'logout')
            el15 = driver.find_element_by_id("com.kt.ollehfamilybox:id/iv_navigation_logout")
            el15.click()
            el16 = driver.find_element_by_id("com.kt.ollehfamilybox:id/btn_common_dialog_right")
            el16.click()
            '''
            wait = WebDriverWait(driver, 200)
            result.setResult('f', 'done')

            time.sleep(3)
            util.closeRecentApp()

        except Exception as ex:
            logger.error('[' + result.getTestId() + ']_s__')
            logger.exception(ex)
            logger.error('[' + result.getTestId() + ']_e__')
Example #14
0
import util
import time

fps_cnt = 0
fps_t = time.time()

while True:
    util.screenshot(region=(708, 391, 120, 30))
    fps_cnt += 1
    now_t = time.time()

    if now_t - fps_t > 1:
        print('fps %.2f' % (fps_cnt / (now_t - fps_t)), end='\r')
        fps_cnt = 0
        fps_t = time.time()
Example #15
0
    def main_loop(self):
        dr = self.driver
        #切换脚本输入法
        dr.press_keycode(63)
        time.sleep(1)
        dr.find_element_by_name(
            "Appium Android Input Manager for Unicode").click()
        time.sleep(1)
        dr.press_keycode(3)
        time.sleep(1)
        dr.find_element_by_name("Chrome").click()
        time.sleep(1)
        while True:
            try:
                WebDriverWait(dr, 10).until(lambda d: d.find_elements_by_xpath(
                    "//android.view.View[@content-desc='兑换']"))[13].click()
                time.sleep(1)
                cdk = ""
                WebDriverWait(
                    dr,
                    60).until(lambda d: d.find_element_by_name("恭喜你!成功领取复活币"))
                time.sleep(1)
                edts = WebDriverWait(
                    dr, 15).until(lambda d: d.find_elements_by_class_name(
                        "android.widget.EditText"))
                cdk = edts[0].get_attribute("name")
                WebDriverWait(dr, 10).until(lambda d: d.find_element_by_xpath(
                    "//android.view.View[@content-desc='× 关闭']")).click()
                time.sleep(1)
                WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id(
                    "com.android.chrome:id/tab_switcher_button")).click()
                time.sleep(1)
                dr.tap(300, 1120)
                time.sleep(1)
                edts = WebDriverWait(
                    dr, 15).until(lambda d: d.find_elements_by_class_name(
                        "android.widget.EditText"))
                edts[0].click()
                for i in range(20):
                    dr.press_keycode(67)
                time.sleep(1)
                edts[0].send_keys(cdk)
                time.sleep(1)
                WebDriverWait(dr, 10).until(lambda d: d.find_element_by_xpath(
                    "//android.view.View[@content-desc='看不清楚,换一张']")).click()
                time.sleep(5)
                edts[1].click()
                for i in range(5):
                    dr.press_keycode(67)
                time.sleep(2)
                for _ in range(10):
                    screenshot("/sdcard/screenshot.png")
                    run_qpy2_script("get_captchaimg_cdk.py")
                    imgcaptcha = self.uuwise()
                    if imgcaptcha is None:
                        print("getimgcaptcha failed")
                        WebDriverWait(
                            dr, 10).until(lambda d: d.find_element_by_xpath(
                                "//android.view.View[@content-desc='看不清楚,换一张']"
                            )).click()
                        time.sleep(1)
                        edts[1].click()
                        for i in range(5):
                            dr.press_keycode(67)
                        time.sleep(1)
                        continue
                    edts[1].send_keys(imgcaptcha)
                    WebDriverWait(dr,
                                  10).until(lambda d: d.find_element_by_xpath(
                                      "//android.view.View[@content-desc='确定']"
                                  )).click()
                    try:
                        WebDriverWait(
                            dr, 5).until(lambda d: d.find_element_by_name(
                                "对不起,验证码错误,请重新输入!"))
                        WebDriverWait(dr, 15).until(
                            lambda d: d.find_element_by_name("确定")).click()
                        time.sleep(1)
                        WebDriverWait(
                            dr, 10).until(lambda d: d.find_element_by_xpath(
                                "//android.view.View[@content-desc='看不清楚,换一张']"
                            )).click()
                        time.sleep(1)
                        edts[1].click()
                        for i in range(5):
                            dr.press_keycode(67)
                        time.sleep(1)
                    except TimeoutException:
                        WebDriverWait(dr, 15).until(
                            lambda d: d.find_element_by_name("确定")).click()
                        time.sleep(1)
                        break
                    WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id(
                        "com.android.chrome:id/tab_switcher_button")).click()
                    time.sleep(1)
                    dr.tap(300, 300)
                    time.sleep(1)

            except Exception as e:
                print("somting wrong")
                print(e)
            finally:
                pass
            print("Again\n")
        return self.exit
Example #16
0
 def signup(self):
     dr = self.driver
     WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id(
         "com.qq.ac.android:id/container_header")).click()
     time.sleep(1)
     #QQ登录
     try:
         WebDriverWait(dr, 10).until(lambda d: d.find_element_by_id(
             "com.qq.ac.android:id/qq_login")).click()
         time.sleep(1)
     except TimeoutException:
         pass
     #进入QQ登录界面
     WebDriverWait(dr, 60).until(
         lambda d: d.find_element_by_id("com.tencent.mobileqq:id/name"))
     time.sleep(1)
     try:
         with open('/sdcard/1/qq.txt', 'r', encoding='utf-8') as f:
             tfile = "/sdcard/1/qq.txt"
             strqq = f.read()
     except:
         with open('D:/brush/slave/scripts/doc/qq.txt',
                   'r',
                   encoding='utf-8') as f:
             tfile = "D:/brush/slave/scripts/doc/qq.txt"
             strqq = f.read()
     match = re.search(r'notuse,(\d+,[0-9a-zA-Z\_\@]+)', strqq)
     if match:
         self.phone = re.search(r'notuse,(\d+)', match.group(0)).group(1)
         self.pwd = re.search(r'notuse,\d+,([0-9a-zA-Z\_\@]+)',
                              match.group(0)).group(1)
         #修改标志QQ已使用
         try:
             lines = open(tfile, 'r').readlines()
             flen = len(lines)
             for i in range(flen):
                 if match.group(0) in lines[i]:
                     usetime = '(time %s.%s  %s:%s:%s)' % (
                         time.localtime().tm_mon, time.localtime().tm_mday,
                         time.localtime().tm_hour, time.localtime().tm_min,
                         time.localtime().tm_sec)
                     modify = 'use,' + match.group(1) + " " + usetime
                     lines[i] = lines[i].replace(match.group(0), modify)
                     break
             open(tfile, 'w').writelines(lines)
         except Exception as e:
             print(e)
     else:
         #帐号已用完
         dr.press_keycode(4)
         time.sleep(1)
         dr.press_keycode(4)
         time.sleep(1)
         return self.do
     edit = WebDriverWait(dr, 15).until(
         lambda d: d.find_elements_by_class_name("android.widget.EditText"))
     edit[0].send_keys(self.phone)
     time.sleep(1)
     edit[1].send_keys(self.pwd)
     time.sleep(1)
     WebDriverWait(
         dr, 15).until(lambda d: d.find_element_by_name("登 录")).click()
     time.sleep(5)
     try:
         for _ in range(5):
             WebDriverWait(
                 dr, 60).until(lambda d: d.find_element_by_name("看不清?换一张"))
             time.sleep(5)
             screenshot("/sdcard/screenshot.png")
             run_qpy2_script("get_captchaimg_qqdongman.py")
             imgcaptcha = self.uuwise()
             if imgcaptcha is None:
                 print("getimgcaptcha failed")
                 self.try_count += 1
                 if self.try_count > 5:
                     self.try_count = 0
                     return self.exit
                 dr.press_keycode(4)
                 time.sleep(1)
                 dr.press_keycode(4)
                 time.sleep(1)
                 return self.signup
             dr.press_keycode(4)
             time.sleep(5)
             WebDriverWait(
                 dr,
                 15).until(lambda d: d.find_element_by_name("登 录")).click()
             time.sleep(1)
             WebDriverWait(
                 dr, 30).until(lambda d: d.find_element_by_name("看不清?换一张"))
             time.sleep(1)
             edts = WebDriverWait(
                 dr, 15).until(lambda d: d.find_element_by_class_name(
                     "android.widget.EditText"))
             edts.send_keys(imgcaptcha)
             WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id(
                 "com.tencent.mobileqq:id/ivTitleBtnRightText")).click()
             time.sleep(5)
             try:
                 #图片验证码是否正确
                 WebDriverWait(
                     dr,
                     10).until(lambda d: d.find_element_by_name("看不清?换一张"))
                 time.sleep(1)
             except TimeoutException:
                 break
         #注册成功页面检测
         WebDriverWait(dr, 60).until(lambda d: d.find_element_by_id(
             "com.qq.ac.android:id/tab_icon_recommend"))
         time.sleep(1)
         #记录帐号密码
         try:
             with open('/sdcard/1/user%s.log' % self.appname_en, 'a') as f:
                 f.write('\nimei:%s,%s,%s (time %s.%s  %s:%s:%s)' %
                         (self.imei, self.phone, self.pwd,
                          time.localtime().tm_mon, time.localtime().tm_mday,
                          time.localtime().tm_hour, time.localtime().tm_min,
                          time.localtime().tm_sec))
         except:
             with open(
                     'D:/brush/slave/scripts/doc/user%s.log' %
                     self.appname_en, 'a') as f:
                 f.write('\nimei:%s,%s,%s (time %s.%s  %s:%s:%s)' %
                         (self.imei, self.phone, self.pwd,
                          time.localtime().tm_mon, time.localtime().tm_mday,
                          time.localtime().tm_hour, time.localtime().tm_min,
                          time.localtime().tm_sec))
         time.sleep(1)
     except TimeoutException:
         try:
             WebDriverWait(dr, 5).until(lambda d: d.find_element_by_id(
                 "com.qq.ac.android:id/tab_icon_center"))
             time.sleep(1)
             return self.do
         except TimeoutException:
             pass
         #修改标志QQ使用失败
         try:
             lines = open(tfile, 'r').readlines()
             flen = len(lines)
             for i in range(flen):
                 if modify in lines[i]:
                     lines[i] = lines[i].replace(modify, modify + ',false')
                     break
             open(tfile, 'w').writelines(lines)
         except Exception as e:
             print(e)
         screenshot(
             "/sdcard/error/%s.png" %
             (str(time.localtime().tm_mon) + str(time.localtime().tm_mday) +
              str(time.localtime().tm_hour) + str(time.localtime().tm_min) +
              str(time.localtime().tm_sec)))
         time.sleep(5)
         self.try_count += 1
         if self.try_count > 5:
             self.try_count = 0
             return self.exit
         dr.press_keycode(4)
         time.sleep(1)
         dr.press_keycode(4)
         time.sleep(1)
         return self.signup
     return self.do
Example #17
0
from util import FPSLimit, screenshot, init_serial, image_to_arduino

OLED_WIDTH = 128
OLED_HEIGHT = 64

FPS = 10

ARDUINO_PATH = "/dev/ttyACM0"  #maybe USB0
BAUDRATE = 115200

fpslimit = FPSLimit(FPS)

init_serial(ARDUINO_PATH, BAUDRATE)

while True:
    img = screenshot(OLED_WIDTH, OLED_HEIGHT)
    image_to_arduino(img)
    next(fpslimit)
Example #18
0
    def test_search_field(self):
        logger = appLogger.getLogger(__name__)

        try:

            result.setResult('m', 'start')

            driver = self.driver
            result.setResult('m', 'conn')
            wait = WebDriverWait(driver, 20)

            result.setResult('m', 'boot')
            util.clickElementById(driver, "com.olleh.android.oc2:id/check_all")
            util.clickElementById(
                driver, "com.olleh.android.oc2:id/mainPermission_btn")
            util.clickElementByIdWithCnt(
                driver,
                "com.android.packageinstaller:id/permission_allow_button", 3)
            util.clickElementById(driver,
                                  "com.olleh.android.oc2:id/guide_start")
            util.clickElementByXPath(
                driver,
                "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout"
            )

            result.setResult('m', 'login')
            util.clickElementById(driver,
                                  "com.olleh.android.oc2:id/Leftnavi_login")

            try:
                el6_1 = driver.find_element_by_id(
                    "com.olleh.android.oc2:id/spl_btn_other_id")
                el6_1.click()

            except NoSuchElementException:
                print("no one touch btn!")

            util.sendKeyElementById(driver,
                                    "com.olleh.android.oc2:id/spl_edit_id",
                                    prop.loginId)
            util.sendKeyElementById(driver,
                                    "com.olleh.android.oc2:id/spl_edit_pwd",
                                    prop.loginpwd)
            util.clickElementById(driver,
                                  "com.olleh.android.oc2:id/spl_btn_login")

            util.screenshot("m.png")

            util.clickElementById(driver,
                                  "com.olleh.android.oc2:id/left_rating_img")
            util.clickElementById(driver, "com.olleh.android.oc2:id/my_back")
            util.clickElementById(driver, "com.olleh.android.oc2:id/viewcell")

            result.setResult('m', 'card')
            util.clickElementById(driver, "com.olleh.android.oc2:id/main_card")
            util.clickElementById(
                driver, "com.olleh.android.oc2:id/kpay_card_close_button")

            result.setResult('m', 'logout')
            util.clickElementByXPath(
                driver,
                "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout"
            )
            util.clickElementByXPath(
                driver,
                "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout[1]/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.RelativeLayout[1]/android.widget.LinearLayout/android.widget.LinearLayout[4]/android.widget.ImageView"
            )
            util.clickElementById(driver,
                                  "com.olleh.android.oc2:id/set_logout_btn")
            '''
            el1 = driver.find_element_by_id("com.olleh.android.oc2:id/check_all")
            el1.click()
            el2 = driver.find_element_by_id("com.olleh.android.oc2:id/mainPermission_btn")
            el2.click()
            el3 = driver.find_element_by_id("com.android.packageinstaller:id/permission_allow_button")
            el3.click()
            el3.click()
            el3.click()
            el4 = driver.find_element_by_id("com.olleh.android.oc2:id/guide_start")
            el4.click()

            el5 = driver.find_element_by_xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout")
            el5.click()

            result.setResult('m', 'login')
            el6 = driver.find_element_by_id("com.olleh.android.oc2:id/Leftnavi_login")
            el6.click()

            try :
                el6_1 = driver.find_element_by_id("com.olleh.android.oc2:id/spl_btn_other_id")
                el6_1.click()

            except NoSuchElementException :
                print ("no one touch btn!")

            el7 = driver.find_element_by_id("com.olleh.android.oc2:id/spl_edit_id")
            el7.send_keys(prop.loginId)
            el8 = driver.find_element_by_id("com.olleh.android.oc2:id/spl_edit_pwd")
            el8.send_keys(prop.loginpwd)
            el9 = driver.find_element_by_id("com.olleh.android.oc2:id/spl_btn_login")
            el9.click()

            el10 = driver.find_element_by_id("com.olleh.android.oc2:id/left_rating_img")
            el10.click()
            el11 = driver.find_element_by_id("com.olleh.android.oc2:id/my_back")
            el11.click()
            el12 = driver.find_element_by_id("com.olleh.android.oc2:id/viewcell")
            el12.click()

            result.setResult('m', 'card')
            el13 = driver.find_element_by_id("com.olleh.android.oc2:id/main_card")
            el13.click()

            el14 = driver.find_element_by_id("com.olleh.android.oc2:id/kpay_card_close_button")
            el14.click()

            result.setResult('m', 'logout')
            el15 = driver.find_element_by_xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout")
            el15.click()
            el16 = driver.find_element_by_xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout[1]/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.RelativeLayout[1]/android.widget.LinearLayout/android.widget.LinearLayout[4]/android.widget.ImageView")
            el16.click()
            el17 = driver.find_element_by_id("com.olleh.android.oc2:id/set_logout_btn")
            el17.click()

            '''

            wait = WebDriverWait(driver, 200)
            result.setResult('m', 'done')

            time.sleep(3)
            util.closeRecentApp()

        except Exception as ex:
            logger.error('[' + result.getTestId() + ']_s__')
            logger.exception(ex)
            logger.error('[' + result.getTestId() + ']_e__')
Example #19
0
def hasObstacle():
    im = util.screenshot(region=(x, y, w, h))
    return (83, 83, 83) in im.im
Example #20
0
 def signup(self):
     dr = self.driver
     WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id(
         "com.yixia.videoeditor:id/login_weibo_button")).click()
     time.sleep(1)
     #进入微博登录界面
     WebDriverWait(dr, 60).until(lambda d: d.find_element_by_id(
         "com.sina.weibo:id/etLoginUsername"))
     time.sleep(1)
     try:
         with open('/sdcard/1/weibo.txt', 'r', encoding='utf-8') as f:
             tfile = "/sdcard/1/weibo.txt"
             strqq = f.read()
     except:
         with open('D:/brush/slave/scripts/doc/weibo.txt',
                   'r',
                   encoding='utf-8') as f:
             tfile = "D:/brush/slave/scripts/doc/weibo.txt"
             strqq = f.read()
     match = re.search(r'notuse,([0-9a-zA-Z\.\@]+,[0-9a-zA-Z\_\@]+)', strqq)
     if match:
         self.phone = re.search(r'notuse,([0-9a-zA-Z\.\@]+)',
                                match.group(0)).group(1)
         self.pwd = re.search(r'notuse,[0-9a-zA-Z\.\@]+,([0-9a-zA-Z\_\@]+)',
                              match.group(0)).group(1)
         #修改标志QQ已使用
         try:
             lines = open(tfile, 'r').readlines()
             flen = len(lines)
             for i in range(flen):
                 if match.group(0) in lines[i]:
                     usetime = '(time %s.%s  %s:%s:%s)' % (
                         time.localtime().tm_mon, time.localtime().tm_mday,
                         time.localtime().tm_hour, time.localtime().tm_min,
                         time.localtime().tm_sec)
                     modify = 'use,' + match.group(1) + " " + usetime
                     lines[i] = lines[i].replace(match.group(0), modify)
                     break
             open(tfile, 'w').writelines(lines)
         except Exception as e:
             print(e)
     else:
         #帐号已用完
         dr.press_keycode(4)
         time.sleep(1)
         dr.press_keycode(4)
         time.sleep(1)
         return self.do
     edit = WebDriverWait(dr, 15).until(
         lambda d: d.find_elements_by_class_name("android.widget.EditText"))
     edit[0].send_keys(self.phone)
     time.sleep(1)
     edit[1].send_keys(self.pwd)
     time.sleep(1)
     WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id(
         "com.sina.weibo:id/bnLogin")).click()
     time.sleep(5)
     try:
         for _ in range(5):
             WebDriverWait(dr, 60).until(lambda d: d.find_element_by_id(
                 "com.sina.weibo:id/iv_access_image"))
             time.sleep(5)
             screenshot("/sdcard/screenshot.png")
             run_qpy2_script("get_captchaimg_sina.py")
             imgcaptcha = self.uuwise()
             if imgcaptcha is None:
                 print("getimgcaptcha failed")
                 self.try_count += 1
                 if self.try_count > 5:
                     self.try_count = 0
                     return self.exit
                 dr.press_keycode(4)
                 time.sleep(1)
                 dr.press_keycode(4)
                 time.sleep(1)
                 return self.signup
             edts = WebDriverWait(
                 dr, 15).until(lambda d: d.find_element_by_class_name(
                     "android.widget.EditText"))
             edts.send_keys(imgcaptcha)
             WebDriverWait(
                 dr,
                 15).until(lambda d: d.find_element_by_name("确定")).click()
             time.sleep(5)
             try:
                 #图片验证码是否正确
                 WebDriverWait(dr, 10).until(lambda d: d.find_element_by_id(
                     "com.sina.weibo:id/iv_access_image"))
                 time.sleep(1)
             except TimeoutException:
                 break
         #注册成功页面检测
         WebDriverWait(dr, 60).until(lambda d: d.find_element_by_id(
             "com.sina.weibo:id/bnLogin")).click()
         time.sleep(1)
         WebDriverWait(dr, 120).until(lambda d: d.find_element_by_id(
             "com.yixia.videoeditor:id/titleLeft")).click()
         time.sleep(1)
         #记录帐号密码
         try:
             with open('/sdcard/1/user%s.log' % self.appname_en, 'a') as f:
                 f.write('\nimei:%s,%s,%s (time %s.%s  %s:%s:%s)' %
                         (self.imei, self.phone, self.pwd,
                          time.localtime().tm_mon, time.localtime().tm_mday,
                          time.localtime().tm_hour, time.localtime().tm_min,
                          time.localtime().tm_sec))
         except:
             with open(
                     'D:/brush/slave/scripts/doc/user%s.log' %
                     self.appname_en, 'a') as f:
                 f.write('\nimei:%s,%s,%s (time %s.%s  %s:%s:%s)' %
                         (self.imei, self.phone, self.pwd,
                          time.localtime().tm_mon, time.localtime().tm_mday,
                          time.localtime().tm_hour, time.localtime().tm_min,
                          time.localtime().tm_sec))
         time.sleep(1)
         self.issign = True
     except TimeoutException:
         try:
             WebDriverWait(dr, 5).until(lambda d: d.find_element_by_id(
                 "com.sina.weibo:id/bnLogin")).click()
             time.sleep(1)
             WebDriverWait(dr, 120).until(lambda d: d.find_element_by_id(
                 "com.yixia.videoeditor:id/titleLeft")).click()
             time.sleep(1)
             #记录帐号密码
             try:
                 with open('/sdcard/1/user%s.log' % self.appname_en,
                           'a') as f:
                     f.write(
                         '\nimei:%s,%s,%s (time %s.%s  %s:%s:%s)' %
                         (self.imei, self.phone, self.pwd,
                          time.localtime().tm_mon, time.localtime().tm_mday,
                          time.localtime().tm_hour, time.localtime().tm_min,
                          time.localtime().tm_sec))
             except:
                 with open(
                         'D:/brush/slave/scripts/doc/user%s.log' %
                         self.appname_en, 'a') as f:
                     f.write(
                         '\nimei:%s,%s,%s (time %s.%s  %s:%s:%s)' %
                         (self.imei, self.phone, self.pwd,
                          time.localtime().tm_mon, time.localtime().tm_mday,
                          time.localtime().tm_hour, time.localtime().tm_min,
                          time.localtime().tm_sec))
             time.sleep(1)
             self.issign = True
             return self.do
         except TimeoutException:
             pass
         #修改标志QQ使用失败
         try:
             lines = open(tfile, 'r').readlines()
             flen = len(lines)
             for i in range(flen):
                 if modify in lines[i]:
                     lines[i] = lines[i].replace(modify, modify + ',false')
                     break
             open(tfile, 'w').writelines(lines)
         except Exception as e:
             print(e)
         screenshot(
             "/sdcard/error/%s.png" %
             (str(time.localtime().tm_mon) + str(time.localtime().tm_mday) +
              str(time.localtime().tm_hour) + str(time.localtime().tm_min) +
              str(time.localtime().tm_sec)))
         time.sleep(5)
         self.try_count += 1
         if self.try_count > 5:
             self.try_count = 0
             return self.exit
         dr.press_keycode(4)
         time.sleep(1)
         dr.press_keycode(4)
         time.sleep(1)
         return self.signup
     return self.do
Example #21
0
 def signup(self):
     dr = self.driver
     pwd_li = [
         "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "1", "2", "3",
         "4", "5", "6", "7", "8", "9", "0", "a", "b", "c", "d", "e", "f",
         "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
         "t", "u", "v", "w", "x", "y", "z"
     ]
     self.pwd = ""
     for _ in range(random.randint(6, 8)):
         self.pwd += choice(pwd_li)
     try:
         #进入注册页面
         WebDriverWait(dr, 10).until(lambda d: d.find_element_by_id(
             "com.sports.baofeng:id/user_login_reg")).click()
         time.sleep(5)
         #选择接码平台获取手机号码
         edts = WebDriverWait(
             dr, 60).until(lambda d: d.find_elements_by_class_name(
                 "android.widget.EditText"))
         self.phone = self.code.getPhone()
         #输入手机号码
         edts[0].send_keys(self.phone)
         time.sleep(1)
         #输入密码
         edts[1].send_keys(self.pwd)
         time.sleep(1)
         for i in range(3):
             screenshot("/sdcard/screenshot.png")
             # run_qpy2_script("get_captchaimg_baofeng_4c.py")
             time.sleep(1)
             dr.press_keycode(3)
             time.sleep(1)
             WebDriverWait(dr, 15).until(
                 lambda d: d.find_element_by_name("QPython")).click()
             time.sleep(1)
             WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id(
                 "com.hipipal.qpyplus:id/whip_logo")).click()
             time.sleep(1)
             WebDriverWait(dr, 15).until(
                 lambda d: d.find_element_by_name("运行脚本")).click()
             time.sleep(1)
             WebDriverWait(dr, 15).until(lambda d: d.find_element_by_name(
                 "get_captchaimg_baofeng_4c.py")).click()
             time.sleep(5)
             WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id(
                 "android:id/action_bar_spinner")).click()
             time.sleep(1)
             WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id(
                 "com.hipipal.qpyplus:id/window_list_close")).click()
             time.sleep(1)
             dr.press_keycode(3)
             time.sleep(1)
             imgcaptcha = self.uuwise()
             if imgcaptcha is None:
                 print("getimgcaptcha failed")
                 self.try_count += 1
                 if self.try_count > 5:
                     self.try_count = 0
                     return self.exit
                 dr.press_keycode(4)
                 time.sleep(1)
                 return self.signup
             edts[2].send_keys(imgcaptcha)
             time.sleep(1)
             #点击获取验证码按钮
             WebDriverWait(dr, 5).until(lambda d: d.find_element_by_xpath(
                 "//android.view.View[@content-desc='免费获取验证码']")).click()
             time.sleep(1)
             try:
                 #图片验证码是否正确
                 WebDriverWait(
                     dr, 10
                 ).until(lambda d: d.find_element_by_xpath(
                     "//android.view.View[@content-desc='验证码已下发到你手机上,请查收!']"
                 ))
                 time.sleep(1)
                 break
             except TimeoutException:
                 WebDriverWait(
                     dr, 5).until(lambda d: d.find_element_by_xpath(
                         "//android.view.View[@content-desc='换一张']")).click(
                         )
                 time.sleep(5)
         #选择接码平台获取验证码
         #验证码:908511  暴风影音用户您正在进行手机号注册验证操作,请在1小时内完成,请勿泄露,如非本人操作请忽略。【暴风】
         regrex = r'验证码:(\d+)'
         captcha = self.code.waitForMessage(regrex, self.phone)
         if captcha is None:
             print("getMessage failed,try_count:%s" % self.try_count)
             #释放号码
             self.code.releasePhone(self.phone)
             self.try_count += 1
             if self.try_count > 5:
                 return self.exit
             dr.press_keycode(4)
             time.sleep(1)
             return self.signup
         #输入验证码
         edts[3].send_keys(captcha)
         time.sleep(1)
         #点击完成按钮按钮
         WebDriverWait(dr, 5).until(lambda d: d.find_element_by_xpath(
             "//android.view.View[@content-desc='注册']")).click()
         time.sleep(1)
         #检测注册成功进入下一步
         WebDriverWait(dr, 60).until(
             lambda d: d.find_element_by_id("com.sports.baofeng:id/tv_me"))
         time.sleep(1)
         #记录帐号密码
         try:
             with open('/sdcard/1/user%s.log' % self.appname_en, 'a') as f:
                 f.write('\nimei:%s,%s,%s (time %s.%s  %s:%s:%s)' %
                         (self.imei, self.phone, self.pwd,
                          time.localtime().tm_mon, time.localtime().tm_mday,
                          time.localtime().tm_hour, time.localtime().tm_min,
                          time.localtime().tm_sec))
         except:
             with open(
                     'D:/brush/slave/scripts/doc/user%s.log' %
                     self.appname_en, 'a') as f:
                 f.write('\nimei:%s,%s,%s (time %s.%s  %s:%s:%s)' %
                         (self.imei, self.phone, self.pwd,
                          time.localtime().tm_mon, time.localtime().tm_mday,
                          time.localtime().tm_hour, time.localtime().tm_min,
                          time.localtime().tm_sec))
         time.sleep(1)
         return self.do
     except Exception as e:
         print("error in getPhone,try_count:%s" % self.try_count)
         self.try_count += 1
         if self.try_count > 5:
             return self.exit
         dr.press_keycode(4)
         time.sleep(2)
         return self.signup