def run_with_rpabrowser(rh, sheet): print("Running RPA Challenge with RPA Browser (Selenium)") browser = Browser() browser.open_available_browser("http://www.rpachallenge.com", headless=True) browser.click_button_when_visible("//button[text()='Start']") for row in sheet: myeval(browser, '//input[@ng-reflect-name="labelFirstName"]', row["First Name"]) myeval(browser, '//input[@ng-reflect-name="labelLastName"]', row["Last Name"]) myeval( browser, '//input[@ng-reflect-name="labelCompanyName"]', row["Company Name"], ) myeval(browser, '//input[@ng-reflect-name="labelRole"]', row["Role in Company"]) myeval(browser, '//input[@ng-reflect-name="labelAddress"]', row["Address"]) myeval(browser, '//input[@ng-reflect-name="labelEmail"]', row["Email"]) myeval( browser, '//input[@ng-reflect-name="labelPhone"]', str(row["Phone Number"]) ) browser.execute_javascript( """document.querySelector('input[type="submit"]').click();""" ) result = browser.execute_javascript( """return document.querySelector('.message2').textContent;""" ) rh.check_for_new_record(browser, result) browser.close_browser()
def request_response(self, formspec=None): self.start_server() if formspec: formdata = open(formspec, "rb") else: formdata = json.dumps(self.custom_form) headers = { "Accept": "application/json", "Content-Type": "application/json" } requests.post( f"{self.attended_server}/formspec", data=formdata, headers=headers, ) br = Browser() br.open_browser(f"{self.attended_server}/form.html") br.set_window_size(600, 800) headers = {"Prefer": "wait=120"} response_json = None # etag = None while True: # if etag: # headers['If-None-Match'] = etag headers["If-None-Match"] = "2434432243" response = requests.get(f"{self.attended_server}/requestresponse", headers=headers) # etag = response.headers.get("ETag") if response.status_code == 200: try: response_json = response.json() break except JSONDecodeError: pass elif response.status_code != 304: # back off if the server is throwing errors time.sleep(60) continue time.sleep(1) br.close_browser() return response_json
def request_response(self, formspec: str = None, window_width: int = 600, window_height: int = 1000) -> dict: """Start server and show form. Waits for user response. :param formspec: form json specification file, defaults to None :param window_width: window width in pixels, defaults to 600 :param window_height: window height in pixels, defaults to 1000 :return: form response Example. .. code-block:: robotframework Create Form ${CURDIR}/${/}myform.json &{response} Request Response """ self._start_attended_server() if self.custom_form is None: self.create_form("Requesting response") if formspec: formdata = open(formspec, "rb") else: formdata = json.dumps(self.custom_form) headers = { "Accept": "application/json", "Content-Type": "application/json" } requests.post( f"{self.server_address}/formspec", data=formdata, headers=headers, ) response_json = {} try: br = Browser() br.open_available_browser(f"{self.server_address}/form.html") br.set_window_size(window_width, window_height) headers = {"Prefer": "wait=120"} # etag = None while True: # if etag: # headers['If-None-Match'] = etag headers["If-None-Match"] = "2434432243" response = requests.get( f"{self.server_address}/requestresponse", headers=headers) # etag = response.headers.get("ETag") if response.status_code == 200: try: response_json = response.json() break except JSONDecodeError: break elif response.status_code != 304: # back off if the server is throwing errors time.sleep(10) continue time.sleep(1) finally: br.close_browser() self._stop_attended_server() return response_json