Merge branch 'feature/playwright' of bitbucket.org:panleicim/appointement_modem_pool into feature/playwright
This commit is contained in:
+21
-10
@@ -28,6 +28,7 @@ CONFIRMED_MESSAGE = "Your request for a Leather Goods appointment has been regis
|
||||
class CommandorPage:
|
||||
def __init__(self):
|
||||
self.otp_value = None
|
||||
self.logger = logging.getLogger("CommandorPage")
|
||||
|
||||
def _run(self, e: threading.Event, proxy, contact: ContactPojo, on_ready_for_otp, on_success):
|
||||
self.contact = contact
|
||||
@@ -41,14 +42,7 @@ class CommandorPage:
|
||||
# elif "firefox" in user_agent.lower():
|
||||
# self.browser = pwright.firefox.launch(headless=False, timeout=90000, proxy=proxy)
|
||||
# else:
|
||||
self.browser = pwright.firefox.launch(headless=False, timeout=90000, proxy=proxy)
|
||||
print("user_agent is " + user_agent)
|
||||
self.page = self.browser.new_page(
|
||||
user_agent=user_agent)
|
||||
# hide webdriver information
|
||||
self.page.add_init_script("""() => Object.defineProperty(navigator,'webdriver',{get: () => undefined}""")
|
||||
self.page.on("load", self._on_page_loaded)
|
||||
self.page.goto(RDV_URL, timeout=90000)
|
||||
self.start_brower(proxy, pwright, user_agent)
|
||||
self._setPhoneCountry()
|
||||
self._setPhoneNumber(contact.phone)
|
||||
self._setName(contact.last_name, contact.first_name)
|
||||
@@ -63,19 +57,36 @@ class CommandorPage:
|
||||
on_ready_for_otp(e, self)
|
||||
event_is_set = e.wait()
|
||||
logging.info('event set: %s', event_is_set)
|
||||
self.fill_otp(self.otp_value)
|
||||
if self.otp_value:
|
||||
self.fill_otp(self.otp_value)
|
||||
self.clickOnValidBtn()
|
||||
otp_sent = self.page.locator(MESSAGE_FIELD_CLASS)
|
||||
otp_sent.wait_for(state='visible')
|
||||
message = self.page.content()
|
||||
print("message is:" + message)
|
||||
time.sleep(2)
|
||||
if CONFIRMED_MESSAGE in message:
|
||||
# publish the successful message
|
||||
print("url is " + self.page.url)
|
||||
self.publish_message_to_queue(contact, message, self.page.url)
|
||||
time.sleep(2)
|
||||
else:
|
||||
print("timeout")
|
||||
self.reset_air_plan_mode()
|
||||
# check and send successful event
|
||||
|
||||
def start_brower(self, proxy, pwright, user_agent):
|
||||
try:
|
||||
self.browser = pwright.firefox.launch(headless=False, timeout=90000, proxy=proxy)
|
||||
print("user_agent is " + user_agent)
|
||||
self.page = self.browser.new_page(
|
||||
user_agent=user_agent)
|
||||
# hide webdriver information
|
||||
self.page.add_init_script("""() => Object.defineProperty(navigator,'webdriver',{get: () => undefined}""")
|
||||
self.page.on("load", self._on_page_loaded)
|
||||
self.page.goto(RDV_URL, timeout=90000)
|
||||
except Exception as error:
|
||||
self.logger.exception(error)
|
||||
|
||||
def start_page(self, proxy, contact: ContactPojo, on_ready_for_otp, on_sucess) -> threading.Event:
|
||||
e = threading.Event()
|
||||
t = threading.Thread(target=self._run, args=(e, proxy, contact, on_ready_for_otp, on_sucess))
|
||||
|
||||
@@ -62,6 +62,8 @@ def timeout_occurred(serial_modem: SerialModem):
|
||||
firebase_store_manager.save_timeout_contact(serial_modem.contact)
|
||||
oracle_log_sender.send_timeout_log(serial_modem)
|
||||
logger.info("will close timeout modem")
|
||||
global thread_event
|
||||
thread_event.set()
|
||||
serial_modem.modem.close()
|
||||
commandor.reset_air_plan_mode()
|
||||
|
||||
@@ -170,17 +172,19 @@ def start_listen():
|
||||
|
||||
|
||||
def on_ready_for_otp(e: Event, commandor: CommandorPage):
|
||||
print("on_ready_for_otp() called.")
|
||||
logger.info("on_ready_for_otp() called.")
|
||||
global thread_event
|
||||
thread_event = e
|
||||
|
||||
|
||||
def start_book():
|
||||
slot_number = 3
|
||||
slot_sum = 8
|
||||
slot_number = 2
|
||||
slot_sum = 2
|
||||
for i in range(slot_number, slot_sum + 1):
|
||||
card_pool.reset()
|
||||
logger.info("will switch to " + str(i))
|
||||
global current_card_pool_slot
|
||||
current_card_pool_slot = i
|
||||
card_pool.switch_to_slot(i)
|
||||
modem_pool = ModemPool(get_devices_ports())
|
||||
modem_pool.reset_all_modems()
|
||||
@@ -189,14 +193,13 @@ def start_book():
|
||||
excel_reader = ExcelHelper()
|
||||
contacts = excel_reader.read_contacts()
|
||||
global current_sim_position
|
||||
current_sim_position = 1
|
||||
current_sim_position = 0
|
||||
for modem in modem_list:
|
||||
current_sim_position = current_sim_position + 1
|
||||
try:
|
||||
# get contact for current modem
|
||||
modem.get_ccid()
|
||||
# find the contact with ccid
|
||||
contact = [contact for contact in contacts if contact.ccid.replace("F", "") == modem.ccid]
|
||||
contact = [contact for contact in contacts if contact.ccid.replace("F", "") == modem.ccid.replace("F", "")]
|
||||
if len(contact) > 0:
|
||||
modem.phone_number = contact[0].phone
|
||||
modem.contact = contact[0]
|
||||
|
||||
+2
-3
@@ -85,8 +85,8 @@ def init_modems() -> list:
|
||||
|
||||
|
||||
def start_book():
|
||||
slot_number = 1
|
||||
slot_sum = 27
|
||||
slot_number = 2
|
||||
slot_sum = 2
|
||||
for i in range(slot_number, slot_sum + 1):
|
||||
card_pool.reset()
|
||||
logger.info("will switch to " + str(i))
|
||||
@@ -94,7 +94,6 @@ def start_book():
|
||||
modem_pool = ModemPool(get_devices_ports())
|
||||
modem_pool.reset_all_modems()
|
||||
modem_list = init_modems()
|
||||
# create listeners for chaque modem
|
||||
# read the contact, and merge the 2 objects together
|
||||
excel_reader = ExcelHelper()
|
||||
contacts = excel_reader.read_contacts()
|
||||
|
||||
Reference in New Issue
Block a user