use playwright to simulate mobile browser
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
import subprocess
|
||||
import time
|
||||
|
||||
import playwright
|
||||
from playwright.sync_api import sync_playwright
|
||||
|
||||
from pojo.contact_pojo import ContactPojo
|
||||
|
||||
# RDV_URL = "https://rendezvousparis.hermes.com/client/register"
|
||||
RDV_URL = "file:///Users/lpan/Downloads/test_appointment.html"
|
||||
|
||||
|
||||
# RDV_URL = "https://www.google.fr"
|
||||
|
||||
|
||||
# RDV_URL = "https://api.ipify.org"
|
||||
|
||||
|
||||
class CommandorPage:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def start_page(self, proxy, contact: ContactPojo):
|
||||
# specifying an explicit component name
|
||||
with sync_playwright() as pwright:
|
||||
self.browser = pwright.chromium.launch(headless=False, timeout=30000, proxy=proxy)
|
||||
self.page = self.browser.new_page(
|
||||
user_agent="Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.87 Mobile Safari/537.36")
|
||||
self.page.goto(RDV_URL)
|
||||
content = self.page.content()
|
||||
self.setPhoneCountry(self.page)
|
||||
self.setPhoneNumber(contact.phone)
|
||||
self.setName(contact.last_name, contact.first_name)
|
||||
self.setEmail(contact.mail)
|
||||
self.setIdNumber(contact.passport)
|
||||
self.checkCgu()
|
||||
self.clickOnValidBtn()
|
||||
# page.on('load', self.on_page_loaded)
|
||||
print(content)
|
||||
time.sleep(100000)
|
||||
|
||||
def on_page_loaded(self):
|
||||
print("page loaded")
|
||||
|
||||
def setPhoneCountry(self, page):
|
||||
page.evaluate("""()=>document.getElementById("phone_country").value = \"FR\" """)
|
||||
|
||||
def setPhoneNumber(self, phoneNumber):
|
||||
self.page.evaluate("""(phoneNumber)=>document.getElementById("phone_number").value =phoneNumber""", phoneNumber)
|
||||
|
||||
def setName(self, lastName, firstName):
|
||||
self.page.evaluate("""(name)=> {
|
||||
document.getElementById("surname").value = name.lastName;
|
||||
document.getElementById("name").value = name.firstName}""", {'lastName': lastName, 'firstName': firstName})
|
||||
|
||||
def setEmail(self, email):
|
||||
self.page.evaluate("""(email)=>document.getElementById("email").value = email""", email)
|
||||
|
||||
def setIdNumber(self, id):
|
||||
self.page.evaluate(""" (id) => document.getElementById("passport_id").value = id""", id)
|
||||
|
||||
def checkCgu(self):
|
||||
self.page.evaluate("""document.getElementById("cgu").checked = true;
|
||||
document.getElementById("processing").checked = true""")
|
||||
|
||||
def clickOnValidBtn(self):
|
||||
self.page.evaluate("""document.getElementsByClassName("btn")[0].click();""")
|
||||
|
||||
def clear_app_data(self):
|
||||
pass
|
||||
|
||||
def send_otp(self, otp: str):
|
||||
self.page.evaluate(""" (otp)=> document.getElementById("sms_code").value = otp""", otp)
|
||||
|
||||
def reset_air_plan_mode(self):
|
||||
subprocess.call(
|
||||
"/Users/panlei/Library/Android/sdk/platform-tools/adb shell settings put global airplane_mode_on 1",
|
||||
shell=True)
|
||||
time.sleep(1)
|
||||
subprocess.call(
|
||||
"/Users/panlei/Library/Android/sdk/platform-tools/adb shell am broadcast -a android.intent.action.AIRPLANE_MODE",
|
||||
shell=True)
|
||||
time.sleep(1)
|
||||
subprocess.call(
|
||||
"/Users/panlei/Library/Android/sdk/platform-tools/adb shell settings put global airplane_mode_on 0",
|
||||
shell=True)
|
||||
time.sleep(1)
|
||||
subprocess.call(
|
||||
"/Users/panlei/Library/Android/sdk/platform-tools/adb shell am broadcast -a android.intent.action.AIRPLANE_MODE",
|
||||
shell=True)
|
||||
time.sleep(10)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
proxy = {
|
||||
"server": "http://gw.ntnt.io:5959",
|
||||
"username": "panleicim-cc-any-sid-1112",
|
||||
"password": "M3PZAXgW5V27"
|
||||
}
|
||||
contact = ContactPojo(phone_number="755667750", passport_number="5123456789", last_name="PAN", first_name="Lei",
|
||||
mail="panleicim@gmail.com", ccid="", position=0)
|
||||
CommandorPage().start_page(None, contact)
|
||||
Reference in New Issue
Block a user