Python: Get var value from keyboard

    Started to write some python script from this year. Here is some basic knowledge for how to get the variable value from keyboard.

class WPTClient(object):

    def __init__(self):

        # Args for all command
        parser = argparse.ArgumentParser(description='Web Page Test Utility')
        parser.add_argument('-e', '--env',
                            help="The env test run against to",
                            default="qa1")

        parser.add_argument('-l', '--label',
                            help="The label for the test",
                            default=datetime.now().strftime('%d-%H-%M'))

        parser.add_argument('-p', '--pages',
                            help="which page you want to test",
                            default="home,srp,vip")

        parser.add_argument('-s', '--script',
                            help="The script will be executed in the test",
                            default='')

        parser.add_argument('-b', '--block',
                            help="The servers will be blocked in the test",
                            default='async-ads.js ads.js advertising prebid adsensecommon.js adnxs.com doubleclick.net pubmatic.com casalemedia.com adservice.google.com adservices.google.com.au demdex.net imrworldwide.com amazonaws.com criteo.com openx.net')

        parser.add_argument('-v', '--vip',
                            help="Specific vip need to be tested",
                            default='')

        parser.add_argument('-r', '--runs',
                            help="Run times for the test",
                            default=3)

        self.config = parser.parse_args()

Then you can use the value like following:

def get_payload(self, page, browser):
        payload = dict()

        # block 3rd party requests
        payload['block'] = self.config.block

        payload['ignoreSSL'] = 1
        payload['runs'] = self.config.runs

        # disable it avoid the performance impaction from video recording
        payload['video'] = 1

        if page == 'vip' and self.config.vip:
            url = self.config.vip
        else:
            url = "{domain}{page}".format(domain=self.env_setup['env'][self.config.env],
                                          page=self.env_setup['paths'][page])
        payload['url'] = url

        display_label = "{page}_{browser}_{label}".format(page=page, browser=browser, label=self.config.label)
        payload['label'] = display_label

        # disable repeat view
        payload['fvonly'] = 1

        # Now we only support AB tests setting
        if bool(self.config.script):
            payload['script'] = self.set_cookie_for_ab_test(url)

        # If it is mobile viewport, mock the 3G fast speed
        if browser == 'iPhone6':
            payload['mobile'] = 1
            payload['mobileDevice'] = 'iPhone6'
            payload['location']='WPT_Local_AU:Chrome.3GFast'

        return payload

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值