Beispiel #1
0
class Process:
    def __init__(self, driver, case_modle, case_id):
        self.driver = driver
        self.functionlibrary = FunctionLibrary(self.driver)
        self.screenshot = Screenshot(self.driver, case_modle, case_id)

    def login(self, username, pasword):
        # self.functionlibrary.ClickByName("我的")
        self.functionlibrary.waitNAME("登录")
        self.functionlibrary.SendKeysByID("com.ygjr.ycd.debug:id/login_et_name", username)
        self.functionlibrary.swipeOnScreenN(0.5, 0.5, 0.5, 0.5, 1)
        self.functionlibrary.SendKeysByID("com.ygjr.ycd.debug:id/login_et_pwd", pasword)
        self.functionlibrary.ClickByName("登录")
        self.functionlibrary.ClickByName("取消")
        self.functionlibrary.waitNAME("首页")
        self.screenshot.takeTakesScreenshot('登录成功截图')
        logger.info("process login execute succeed!")

    def logout(self):
        self.functionlibrary.ClickByName("我的")
        self.functionlibrary.waitNAME("设置中心")
        self.functionlibrary.ClickByName("设置中心")
        self.functionlibrary.ClickByName("退出账号")
        self.functionlibrary.ClickByName("确认")
        self.screenshot.takeTakesScreenshot('推出成功截图')
        logger.info("process logout execute succeed!")
Beispiel #2
0
 def setUp(self):
     # -----实例化基础类------
     driver = Mobile()
     self.driver = driver.driver
     self.functionlibrary = FunctionLibrary(self.driver)
     self.screenshot = Screenshot(self.driver)
     self.process = processed.Process(self.driver)
     self.username_ture = '18519030808'
     self.username_false = '18511030838'
     self.password_ture = 'asdf1234'
     self.password_false = 'asdf1111'
    def run(self, screenshot_page_url):
        if self.user is None:
            logging.warning('Attempting to get screenshot for an empty user')
            return

        # First check if screenshot exists in db already
        parsed_url = urlparse.urlparse(screenshot_page_url)
        screenshot_id = urlparse.parse_qs(parsed_url.query)['id'][0]
        if Screenshot.all().filter('screenshot_id =', screenshot_id).get() is not None:
            logging.debug('Screenshot already exists in database: ' + screenshot_id)
            return

        # Then check if we got 200 from Steam
        page_soup = helpers.request_soup(screenshot_page_url)
        if page_soup is None:
            return
        logging.info('Retrieved screenshot: ' + screenshot_page_url)

        # TODO Smarter check for spoiler tag
        #
        # Apparently the spoiler html element is only on the desktop version
        # so I probably have to schedule a separate task just to search the
        # desktop listings for potential spoilers

        screenshot_src        = page_soup.find('img', class_='userScreenshotImg')['src']
        screenshot_desc       = page_soup.find('h1', class_='captionText').string.strip()
        screenshot_is_spoiler = "spoiler" in screenshot_desc.lower()
        screenshot_is_nsfw    = "nsfw" in screenshot_desc.lower()
        screenshot_game       = page_soup.find(id='gameName').find('a', class_='itemLink').string.strip()

        s = Screenshot(
            parent        = self.user,
            screenshot_id = screenshot_id,
            url           = screenshot_page_url,
            src           = screenshot_src,
            desc          = screenshot_desc,
            game          = screenshot_game,
            is_spoiler    = screenshot_is_spoiler,
            is_nsfw       = screenshot_is_nsfw
        )
        result = s.put()
        if result is db.TransactionFailedError:
            logging.error('Failed to save screenshot for ' + self.user.steam_username + ' id:' + screenshot_id)
        else:
            logging.debug('Successfully saved screenshot for ' + self.user.steam_username + ' id:' + screenshot_id)
Beispiel #4
0
 def ycd360_mobile_setup(self, trade, caseID):
     """
     实例化基础类
     :return:
     """
     self.trade = trade
     self.caseid = caseID
     mobile = Mobile()
     self.driver = mobile.open_app()
     self.functionlibrary = mf(self.driver)
     self.datatools = GetDataTools("易港金融")
     self.module = self.datatools.getExcelDateRowValue(
         self.trade, '案例所属模块', self.caseid)
     self.process = Process(self.driver, self.module, self.caseid)
     self.screenshot = Screenshot(self.driver, self.module, self.caseid)
Beispiel #5
0
 def ycd360_web_setup(self, trade, caseID):
     """
     实例化基础类
     :return:
     """
     self.trade = trade
     self.caseid = caseID
     driver = BrowserEngine()
     self.driver = driver.open_browser()
     self.functionlibrary = wf(self.driver)
     self.datatools = GetDataTools("易港金融")
     self.module = self.datatools.getExcelDateRowValue(
         self.trade, '案例所属模块', self.caseid)
     self.process = Process(self.driver, self.module, self.caseid)
     self.screenshot = Screenshot(self.driver, self.module, self.caseid)
    def collect_screenshot_from_community_portal(
            self,
            url: str,
            wait_time: int = conf.SELENIUM_WAIT_TIME) -> Screenshot:

        logger.info(f'Collecting screenshot from {url}')

        self.driver.get(url)

        WebDriverWait(self.driver, wait_time)

        ss = self.driver.find_element_by_tag_name("body").screenshot_as_base64

        logger.info('Collected screenshot')

        return Screenshot(url=url, b64png=ss, cid=str(uuid.uuid4()))
Beispiel #7
0
    def post(self):
        self.checkChannelKey()
        self.parseTriggerFields()
        self.parseLimit()

        screenshots_query = Screenshot.all()
        screenshots_query.ancestor(self.user)
        screenshots_query.filter('seen_already =', False)
        if not self.user.steam_show_spoilers:
            screenshots_query.filter('is_spoiler =', False)
        if not self.user.steam_show_nsfw:
            screenshots_query.filter('is_nsfw =', False)

        screenshots     = screenshots_query.fetch(self.limit)
        screenshot_data = []
        for screenshot in screenshots:
            screenshot_data.append({
                IFTTT_INGREDIENT_SCREENSHOT_PAGE_KEY:       screenshot.url,
                IFTTT_INGREDIENT_SCREENSHOT_URL_KEY:        screenshot.src,
                IFTTT_INGREDIENT_SCREENSHOT_CAPTION_KEY:    screenshot.desc,
                IFTTT_INGREDIENT_SCREENSHOT_USERNAME_KEY:   self.user.steam_username,
                IFTTT_INGREDIENT_SCREENSHOT_GAME_KEY:       screenshot.game,
                IFTTT_INGREDIENT_META_LABEL_KEY: {
                    IFTTT_INGREDIENT_META_ID_KEY:           screenshot.screenshot_id,
                    IFTTT_INGREDIENT_META_TIMESTAMP_KEY:    int((screenshot.scraped - datetime(1970, 1, 1)).total_seconds())
                }
            })
            screenshot.seen_already = True

        # Save the seen_already flags
        db.put(screenshots)


        self.setResponseHeaders()
        self.response.out.write(json.dumps({
            # Sort by timestsamp because apparently the db query isn't sorted by scraped date
            'data': sorted(screenshot_data, reverse=True, key=lambda k: k[IFTTT_INGREDIENT_META_LABEL_KEY][IFTTT_INGREDIENT_META_TIMESTAMP_KEY])
        }))
Beispiel #8
0
 def __init__(self, driver, case_modle, case_id):
     self.driver = driver
     self.functionlibrary = FunctionLibrary(self.driver)
     self.screenshot = Screenshot(self.driver, case_modle, case_id)
Beispiel #9
0
class TestZZHK(unittest.TestCase):
    def setUp(self):
        # -----实例化基础类------
        driver = Mobile()
        self.driver = driver.driver
        self.functionlibrary = FunctionLibrary(self.driver)
        self.screenshot = Screenshot(self.driver)
        self.process = processed.Process(self.driver)
        self.username_ture = '18519030808'
        self.username_false = '18511030838'
        self.password_ture = 'asdf1234'
        self.password_false = 'asdf1111'

    def test_1login_ture(self):
        '''
        输入正确手机号密码登录
        :return:
        '''
        # -----业务逻辑代码------
        self.functionlibrary.ClickByName("我的")
        is_login = self.functionlibrary.elementIsExist("提现")
        if is_login:
            self.process.logout()
            self.functionlibrary.ClickByName("我的")
        self.functionlibrary.SendKeysByID("com.ygjr.ycd.debug:id/login_et_name", self.username_ture)
        self.functionlibrary.swipeOnScreenN(0.5, 0.5, 0.5, 0.5, 1)
        self.functionlibrary.SendKeysByID("com.ygjr.ycd.debug:id/login_et_pwd", self.password_ture)
        self.functionlibrary.ClickByName("登录")
        self.functionlibrary.ClickByName("取消")
        self.functionlibrary.waitNAME("首页")
        self.screenshot.takeTakesScreenshot('登录成功截图')
        self.process.logout()

    def test_2login_username_false(self):
        '''
        输入错误手机号码真确密码登录
        :return:
        '''
        # -----业务逻辑代码------
        self.functionlibrary.ClickByName("我的")
        is_login = self.functionlibrary.elementIsExist("提现")
        if is_login:
            self.process.logout()
        self.functionlibrary.SendKeysByID("com.ygjr.ycd.debug:id/login_et_name", self.username_false)
        self.functionlibrary.swipeOnScreenN(0.5, 0.5, 0.5, 0.5, 1)
        self.functionlibrary.SendKeysByID("com.ygjr.ycd.debug:id/login_et_pwd", self.password_ture)
        self.functionlibrary.ClickByName("登录")
        self.functionlibrary.CheckByText("com.ygjr.ycd.debug:id/dialog_tv_hint", "用户名或密码错误")
        self.screenshot.takeTakesScreenshot('登录失败截图')

    def test_3login_password_false(self):
        '''
        输入错误手机号正确密码登录
        :return:
        '''
        # -----业务逻辑代码------
        self.functionlibrary.ClickByName("我的")
        is_login = self.functionlibrary.elementIsExist("提现")
        if is_login:
            self.process.logout()
        self.functionlibrary.SendKeysByID("com.ygjr.ycd.debug:id/login_et_name", self.username_ture)
        self.functionlibrary.swipeOnScreenN(0.5, 0.5, 0.5, 0.5, 1)
        self.functionlibrary.SendKeysByID("com.ygjr.ycd.debug:id/login_et_pwd", self.password_false)
        self.functionlibrary.ClickByName("登录")
        self.functionlibrary.CheckByText("com.ygjr.ycd.debug:id/dialog_tv_hint", "用户名或密码错误")
        self.screenshot.takeTakesScreenshot('登录失败截图')

    def tearDown(self):
        """
        测试结束后的操作,这里基本上都是关闭应用程序
        :return:
        """
        self.driver.quit()