improving AndroidEmulator

This commit is contained in:
frankknoll
2022-05-13 12:08:48 +02:00
parent a42e392080
commit 71b73d6309

View File

@@ -107,6 +107,17 @@
" @staticmethod\n",
" def _start():\n",
" os.system(\"/home/frankknoll/Android/Sdk/emulator/emulator -avd Pixel_2_API_30 -no-window &\")\n",
" AndroidEmulator._waitUntilStarted()\n",
" \n",
" @staticmethod\n",
" def _waitUntilStarted():\n",
" while not AndroidEmulator._isStarted():\n",
" time.sleep(1)\n",
"\n",
" @staticmethod\n",
" def _isStarted():\n",
" boot_completed = ! adb shell getprop sys.boot_completed\n",
" return boot_completed[0] == '1'\n",
"\n",
" @staticmethod\n",
" def _stop():\n",
@@ -149,6 +160,21 @@
" return not existsElementWithId(driver, \"wordverify\")\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "da7c965a",
"metadata": {},
"outputs": [],
"source": [
"import time\n",
"import os.path\n",
"\n",
"def waitUntilDownloadHasFinished(file):\n",
" while not os.path.exists(file):\n",
" time.sleep(2)"
]
},
{
"cell_type": "code",
"execution_count": null,
@@ -168,31 +194,8 @@
" textInCaptchaImage = AndroidEmulator.run(lambda: getTextInCaptchaImage(captchaImageFile))\n",
" display('textInCaptchaImage: ', textInCaptchaImage)\n",
" driver.find_element(By.ID, \"verificationCode\").send_keys(textInCaptchaImage)\n",
" driver.find_element(By.CSS_SELECTOR, '[name=\"downloadbut\"]').click()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "aef4d1c3",
"metadata": {},
"outputs": [],
"source": [
"import time\n",
"import os.path\n",
" driver.find_element(By.CSS_SELECTOR, '[name=\"downloadbut\"]').click()\n",
"\n",
"def waitUntilDownloadHasFinished(file):\n",
" while not os.path.exists(file):\n",
" time.sleep(2)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "741ec545",
"metadata": {},
"outputs": [],
"source": [
"def downloadFile(file, driver, maxTries):\n",
" captchaImageFile = 'captchaImage.jpeg'\n",
" tryNum = 1\n",
@@ -205,35 +208,28 @@
" waitUntilDownloadHasFinished(file)\n",
" return True\n",
" else:\n",
" return False\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8eef224c",
"metadata": {},
"outputs": [],
"source": [
"downloadDir = \"/home/frankknoll/Dokumente/Corona/projects/HowBadIsMyBatch/src/VAERS/tmp\"\n",
"file2Download = '2022VAERSData.zip'\n",
" return False\n",
"\n",
"driver = getWebDriver(downloadDir, isHeadless = False)\n",
"driver.get('https://vaers.hhs.gov/eSubDownload/index.jsp?fn=' + file2Download)\n",
"downloadFile(\n",
" file = downloadDir + \"/\" + file2Download,\n",
" driver = driver,\n",
" maxTries = 2)"
"def downloadVAERSFile(file):\n",
" downloadDir = \"/home/frankknoll/Dokumente/Corona/projects/HowBadIsMyBatch/src/VAERS/tmp\"\n",
" driver = getWebDriver(downloadDir, isHeadless = False)\n",
" driver.get('https://vaers.hhs.gov/eSubDownload/index.jsp?fn=' + file)\n",
" isFileDownloaded = downloadFile(\n",
" file = downloadDir + \"/\" + file,\n",
" driver = driver,\n",
" maxTries = 2)\n",
" driver.quit()\n",
" return isFileDownloaded"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "380bcf32",
"id": "9a9e4d1e",
"metadata": {},
"outputs": [],
"source": [
"driver.quit()"
"downloadVAERSFile('2022VAERSData.zip')"
]
},
{