這篇文章主要講解了python如何實(shí)現(xiàn)PageFactory設(shè)計(jì)模式,內(nèi)容清晰明了,對此有興趣的小伙伴可以學(xué)習(xí)一下,相信大家閱讀完之后會有幫助。
創(chuàng)新互聯(lián)是一家集網(wǎng)站建設(shè),桂平企業(yè)網(wǎng)站建設(shè),桂平品牌網(wǎng)站建設(shè),網(wǎng)站定制,桂平網(wǎng)站建設(shè)報(bào)價(jià),網(wǎng)絡(luò)營銷,網(wǎng)絡(luò)優(yōu)化,桂平網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競爭力。可充分滿足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時(shí)我們時(shí)刻保持專業(yè)、時(shí)尚、前沿,時(shí)刻以成就客戶成長自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。前言
pageFactory的設(shè)計(jì)模式能在java里執(zhí)行的原因是java自帶了PageFactory類,而在python中沒有這樣的包,但是已經(jīng)有人寫好了pageFactory在python的包,可以拿來用
pageFactory 用于python支持的py文件
__all__ = ['cacheable', 'callable_find_by', 'property_find_by'] def cacheable_decorator(lookup): def func(self): if not hasattr(self, '_elements_cache'): self._elements_cache = {} # {callable_id: element(s)} cache = self._elements_cache key = id(lookup) if key not in cache: cache[key] = lookup(self) return cache[key] return func cacheable = cacheable_decorator _strategy_kwargs = ['id_', 'xpath', 'link_text', 'partial_link_text', 'name', 'tag_name', 'class_name', 'css_selector'] def _callable_find_by(how, using, multiple, cacheable, context, driver_attr, **kwargs): def func(self): # context - driver or a certain element if context: ctx = context() if callable(context) else context.__get__(self) # or property else: ctx = getattr(self, driver_attr) # 'how' AND 'using' take precedence over keyword arguments if how and using: lookup = ctx.find_elements if multiple else ctx.find_element return lookup(how, using) if len(kwargs) != 1 or list(kwargs.keys())[0] not in _strategy_kwargs: raise ValueError( "If 'how' AND 'using' are not specified, one and only one of the following " "valid keyword arguments should be provided: %s." % _strategy_kwargs) key = list(kwargs.keys())[0]; value = kwargs[key] suffix = key[:-1] if key.endswith('_') else key # find_element(s)_by_xxx prefix = 'find_elements_by' if multiple else 'find_element_by' lookup = getattr(ctx, '%s_%s' % (prefix, suffix)) return lookup(value) return cacheable_decorator(func) if cacheable else func def callable_find_by(how=None, using=None, multiple=False, cacheable=False, context=None, driver_attr='_driver', **kwargs): return _callable_find_by(how, using, multiple, cacheable, context, driver_attr, **kwargs) def property_find_by(how=None, using=None, multiple=False, cacheable=False, context=None, driver_attr='_driver', **kwargs): return property(_callable_find_by(how, using, multiple, cacheable, context, driver_attr, **kwargs))
標(biāo)題名稱:python如何實(shí)現(xiàn)PageFactory設(shè)計(jì)模式-創(chuàng)新互聯(lián)
網(wǎng)站路徑:http://jinyejixie.com/article2/dcjooc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站制作、做網(wǎng)站、外貿(mào)建站、營銷型網(wǎng)站建設(shè)、App開發(fā)、網(wǎng)站導(dǎo)航
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容