示例#1
0
def test_web(args={}):
    try:
        # initialize the error strings array
        errors = []

        # parse the global settings and test method
        # params from the args provided
        settings = args['settings']
        params = args['params']

        # do some selenium specific test stuff ...
        goto_url = params.get('url', 'http://www.google.com')
        lib = WebLib(settings)
        lib.driver.get(goto_url)
        element = lib.driver.find_element_by_id('gbqfq')
        if element == None:
            errors.append('did not find the google input element')
        else:
            logging.info('found the google input element')

        # call the utility method to verify the absence or errors or
        # pack up the error messages if any
        return pytaf_utils.verify(len(errors) == 0,
                                  'there were errors: %s' % errors)
    except Exception as inst:
        logging.error(inst)
        # fail on any exception and include a stack trace
        return (False, pytaf_utils.formatExceptionInfo())
    finally:
        # cleanup
        lib.driver.quit()
示例#2
0
def test_simple_post(args={}):
    ''' example of json parsing from http post '''
    params = args['params']
    settings = args['settings']
    url = params.get('url',"httpbin.org")
    try:
        errors = []
        headers = {}
        request = ''
        locator = "/post"
        lib = ApiLib()
        response = lib.do_post(url, locator, request,
                               settings, headers, False)
        data = json.loads(response['data'])
        print(data)
        origin = data.get('origin', None)
        if origin == None:
            errors.append("did not get expected 'origin' field")
        else:
            print("origin = %s" % origin)

        return pytaf_utils.verify(len(errors) == 0,
                                  'there were errors: %s' % errors)
    except:
        return (False, pytaf_utils.formatExceptionInfo())
示例#3
0
def test_simple_get(args={}):
    '''
        example of json parsing from http get
        http://httpbin.org/

        It echoes the data used in your request for any of these types:

        http://httpbin.org/ip Returns Origin IP.
        http://httpbin.org/user-agent Returns user-agent.
        http://httpbin.org/headers Returns header dict.
        http://httpbin.org/get Returns GET data.
        http://httpbin.org/post Returns POST data.
        http://httpbin.org/put Returns PUT data.
        http://httpbin.org/delete Returns DELETE data
        http://httpbin.org/gzip Returns gzip-encoded data.
        http://httpbin.org/status/:code Returns given HTTP Status code.
        http://httpbin.org/redirect/:n 302 Redirects n times.
        http://httpbin.org/cookies Returns cookie data.
        http://httpbin.org/cookies/set/:name/:value Sets a simple cookie.
        http://httpbin.org/basic-auth/:user/:passwd Challenges HTTPBasic Auth.
        http://httpbin.org/hidden-basic-auth/:user/:passwd 404'd BasicAuth.
        http://httpbin.org/stream/:n Streams n–100 lines.
        http://httpbin.org/delay/:n Delays responding for n–10 seconds.
'''
    params = args['params']
    settings = args['settings']
    url = params.get('url',"httpbin.org")
    try:
        errors = []
        headers = {}
        locator = "/get"
        lib = ApiLib()
        response = lib.do_get(url, locator, settings, headers, False)
        data = json.loads(response['data'])
        print(data)
        origin = data.get('origin', None)
        if origin == None:
            errors.append("did not get expected 'origin' field")
        else:
            print("origin = %s" % origin)

        return pytaf_utils.verify(len(errors) == 0,
                                  'there were errors: %s' % errors)
    except:
        return (False, pytaf_utils.formatExceptionInfo())
示例#4
0
def test_html_get(args={}):
    ''' example using BeautifulSoup to parse html '''
    params = args['params']
    settings = args['settings']
    url = params.get('url',"www.google.com")
    try:
        errors = []
        headers = {}
        locator = "/index.html"
        lib = ApiLib()
        response = lib.do_get(url, locator, settings, headers, False)
        data = response['data']
        soup = BeautifulSoup(data)
        divs = soup.findAll('div')
        for div in divs:
            try:
                print("div style = %s" % div['style'])
            except:
                pass
        return pytaf_utils.verify(len(errors) == 0,
                                'there were errors: %s' % errors)
    except:
        return (False, pytaf_utils.formatExceptionInfo())
示例#5
0
def test_html_get(args={}):
    ''' example using BeautifulSoup to parse html '''
    settings = args['settings']
    url = settings['url']

    try:
        errors = []
        headers = {}
        url = "www.google.com"
        u = "/index.html"
        lib = ApiLib()
        response = lib.do_get(url, u, args['settings'], headers, False)
        data = response['data']
        soup = BeautifulSoup(data)
        divs = soup.findAll('div')
        for d in divs:
            try:
                logging.info("div style = %s" % d['style'])
            except:
                pass
        return pytaf_utils.verify(len(errors) == 0,
                                'there were errors: %s' % errors)
    except:
        return (False, pytaf_utils.formatExceptionInfo())