def test_postIntercepted(self): '''This tests the ability to intercept, and validate intercepted, post requests.''' # Register the request path of the post request to be intercepted mslclient.setInterceptXHR("localhost", "8001", "/services/postservice") # Put text into input box which will be added to post request inputBox = chrome.find_element_by_id('output-box') inputBox.send_keys('POST Example') # Trigger the post request postButton = chrome.find_element_by_id('postRequest') postButton.click() time.sleep(1) # Retrieve all request intercepted that have the provided request path intercepted = json.loads(mslclient.getInterceptedXHR("localhost", "8001", "/services/postservice")) # Validate the method and url of the intercepted request req1 = intercepted['xhr_1'] assert req1['xhr']['method'] == 'POST' assert req1['xhr']['url'] == '/services/postservice' matched = re.match('timestamp=\\d*&text=POST\+Example', req1['post']) assert matched.group(0) is not None assert matched.group(0) == req1['post']
def test_getIntercepted(self): '''This tests the ability to intercept, and validate intercepted, get requests. ''' # Register the request path of the get request to be intercepted mslclient.setInterceptXHR("localhost", "8001", "/services/getservice") # Put text into input box which will be added to get request inputBox = chrome.find_element_by_id('getInput') inputBox.send_keys('GET Example') # Trigger the get request postButton = chrome.find_element_by_id('getRequest') postButton.click() time.sleep(1) # Retrieve all request intercepted that have the provided request path intercepted = json.loads(mslclient.getInterceptedXHR("localhost", "8001", "/services/getservice")) # Validate the method and url of the intercepted request req1 = intercepted['xhr_1'] assert req1['xhr']['method'] == 'GET' assert req1['xhr']['url'] == '/services/getservice?term=GET+Example' assert req1['post'] is None