selenium being fixed
This commit is contained in:
@@ -19,31 +19,14 @@ async def start_workflow(request: Request):
|
||||
data = await request.json()
|
||||
try:
|
||||
bot = AutomationMassHealth(data)
|
||||
result = bot.main_workflow_upto_step2("https://providers.massdhp.com/providers_login.asp")
|
||||
result = bot.main_workflow("https://providers.massdhp.com/providers_login.asp")
|
||||
|
||||
if result.get("status") != "success":
|
||||
return {"status": "error", "message": result.get("message")}
|
||||
|
||||
return result
|
||||
except Exception as e:
|
||||
return {"status": "error", "message": str(e)}
|
||||
|
||||
# Endpoint: Step 2 — Extract the PDF content after manual submission
|
||||
@app.post("/fetch-pdf")
|
||||
async def fetch_pdf():
|
||||
try:
|
||||
bot = AutomationMassHealth.get_last_instance()
|
||||
if not bot:
|
||||
return {"status": "error", "message": "No running automation session"}
|
||||
|
||||
result = bot.reach_to_pdf()
|
||||
|
||||
if result.get("status") != "success":
|
||||
return {"status": "error", "message": result.get("message")}
|
||||
|
||||
return {
|
||||
"status": "success",
|
||||
"pdf_url": result["pdf_url"]
|
||||
}
|
||||
except Exception as e:
|
||||
return {"status": "error", "message": str(e)}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
uvicorn.run(app, host="0.0.0.0", port=5002)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"name": "seleniumservice",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"postinstall": "pip install -r requirements.txt"
|
||||
"postinstall": "pip install -r requirements.txt",
|
||||
"dev": "python agent.py"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,16 +11,11 @@ from datetime import datetime
|
||||
import tempfile
|
||||
import base64
|
||||
import os
|
||||
import requests
|
||||
import json
|
||||
|
||||
class AutomationMassHealth:
|
||||
last_instance = None
|
||||
|
||||
def __init__(self, data):
|
||||
self.headless = False
|
||||
self.driver = None
|
||||
AutomationMassHealth.last_instance = self
|
||||
|
||||
self.data = data
|
||||
self.claim = data.get("claim", {})
|
||||
@@ -36,11 +31,9 @@ class AutomationMassHealth:
|
||||
self.missingTeethStatus = self.claim.get("missingTeethStatus", "")
|
||||
self.missingTeeth = self.claim.get("missingTeeth", {})
|
||||
|
||||
@staticmethod
|
||||
def get_last_instance():
|
||||
return AutomationMassHealth.last_instance
|
||||
|
||||
def config_driver(self):
|
||||
print("caled config")
|
||||
options = webdriver.ChromeOptions()
|
||||
if self.headless:
|
||||
options.add_argument("--headless")
|
||||
@@ -289,13 +282,23 @@ class AutomationMassHealth:
|
||||
except Exception as e:
|
||||
print(f"Error while filling remarks: {e}")
|
||||
return "ERROR:REMARKS FAILED"
|
||||
|
||||
# 5 - close buton
|
||||
try:
|
||||
close_button = wait.until(EC.element_to_be_clickable((By.XPATH, "//input[@type='submit' and @value='Submit Request']")))
|
||||
close_button.click()
|
||||
|
||||
time.sleep(3)
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error while Closing: {e}")
|
||||
return "ERROR:CLOSE FAILED"
|
||||
|
||||
return "Success"
|
||||
|
||||
|
||||
def reach_to_pdf(self):
|
||||
wait = WebDriverWait(self.driver, 30)
|
||||
|
||||
wait = WebDriverWait(self.driver, 90)
|
||||
try:
|
||||
print("Waiting for PDF link to appear on success page...")
|
||||
pdf_link_element = wait.until(
|
||||
@@ -313,10 +316,7 @@ class AutomationMassHealth:
|
||||
full_pdf_url = pdf_relative_url
|
||||
|
||||
print("FULL PDF LINK: ",full_pdf_url)
|
||||
return {
|
||||
"status": "success",
|
||||
"pdf_url": full_pdf_url
|
||||
}
|
||||
return full_pdf_url
|
||||
|
||||
except Exception as e:
|
||||
print(f"ERROR: {str(e)}")
|
||||
@@ -328,27 +328,37 @@ class AutomationMassHealth:
|
||||
finally:
|
||||
if self.driver:
|
||||
self.driver.quit()
|
||||
AutomationMassHealth.last_instance = None
|
||||
|
||||
|
||||
def main_workflow_upto_step2(self, url):
|
||||
self.config_driver()
|
||||
print("Reaching Site :", url)
|
||||
self.driver.maximize_window()
|
||||
self.driver.get(url)
|
||||
time.sleep(3)
|
||||
def main_workflow(self, url):
|
||||
try:
|
||||
self.config_driver()
|
||||
print("Reaching Site :", url)
|
||||
self.driver.maximize_window()
|
||||
self.driver.get(url)
|
||||
time.sleep(3)
|
||||
|
||||
if self.login().startswith("ERROR"):
|
||||
return {"status": "error", "message": "Login failed"}
|
||||
login_result = self.login()
|
||||
if login_result.startswith("ERROR"):
|
||||
return {"status": "error", "message": login_result}
|
||||
|
||||
if self.step1().startswith("ERROR"):
|
||||
return {"status": "error", "message": "Step1 failed"}
|
||||
step1_result = self.step1()
|
||||
if step1_result.startswith("ERROR"):
|
||||
return {"status": "error", "message": step1_result}
|
||||
|
||||
if self.step2().startswith("ERROR"):
|
||||
return {"status": "error", "message": "Step2 failed"}
|
||||
step2_result = self.step2()
|
||||
if step2_result.startswith("ERROR"):
|
||||
return {"status": "error", "message": step2_result}
|
||||
|
||||
reachToPdf_result = self.reach_to_pdf()
|
||||
if reachToPdf_result.startswith("ERROR"):
|
||||
return {"status": "error", "message": reachToPdf_result}
|
||||
|
||||
print("Waiting for user to manually submit form in browser...")
|
||||
return {
|
||||
"status": "waiting_for_user",
|
||||
"message": "Automation paused. Please submit the form manually in browser."
|
||||
}
|
||||
return {
|
||||
"status": "success",
|
||||
"pdf_url": reachToPdf_result
|
||||
}
|
||||
except Exception as e:
|
||||
return {
|
||||
"status": "error",
|
||||
"message": e
|
||||
}
|
||||
|
||||
6
apps/SeleniumService/~/.wdm/drivers.json
Normal file
6
apps/SeleniumService/~/.wdm/drivers.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"win64_chromedriver_137.0.7151.119_for_137.0.7151": {
|
||||
"timestamp": "27/06/2025",
|
||||
"binary_path": "~\\.wdm\\drivers\\chromedriver\\win64\\137.0.7151.119\\chromedriver-win32/chromedriver.exe"
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,27 @@
|
||||
// Copyright 2015 The Chromium Authors
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google LLC nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Reference in New Issue
Block a user