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