[UPD] script selenium: implement configuration and merge script
This commit is contained in:
parent
d7f6c257d2
commit
ed96b2ad01
4 changed files with 273 additions and 544 deletions
|
|
@ -1,44 +1,284 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.support import expected_conditions as EC
|
||||
from selenium.webdriver.support.ui import WebDriverWait
|
||||
|
||||
# Configuration pour lancer Firefox en mode de navigation privée
|
||||
firefox_options = webdriver.FirefoxOptions()
|
||||
firefox_options.add_argument("--private")
|
||||
|
||||
# Définissez la préférence pour les notifications de bureau
|
||||
# 1 signifie "autoriser", 2 signifie "bloquer"
|
||||
firefox_options.set_preference("permissions.default.desktop-notification", 1)
|
||||
|
||||
# Créez une instance du navigateur Firefox avec les options de navigation privée
|
||||
driver = webdriver.Firefox(options=firefox_options)
|
||||
|
||||
# Ouvrez la page web
|
||||
driver.get("http://127.0.0.1:8069/web")
|
||||
|
||||
# Trouvez les éléments du formulaire
|
||||
courriel_input = driver.find_element(By.NAME, "login")
|
||||
mot_de_passe_input = driver.find_element(By.NAME, "password")
|
||||
try:
|
||||
connexion_button = driver.find_element(
|
||||
By.XPATH,
|
||||
"/html/body/div/div/div/form/div[3]/button"
|
||||
# '//button[contains(text(), "Log in")]'
|
||||
def get_config():
|
||||
parser = argparse.ArgumentParser(
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||
description="""Selenium script to open web browser to ERPLibre.""",
|
||||
epilog="""\
|
||||
""",
|
||||
)
|
||||
except Exception:
|
||||
connexion_button = driver.find_element(
|
||||
By.XPATH,
|
||||
"/html/body/div/main/div/form/div[3]/button"
|
||||
# '//button[contains(text(), "Connexion")]'
|
||||
parser.add_argument(
|
||||
"--open_me_devops",
|
||||
action="store_true",
|
||||
help="Open application devops and show entry me.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--open_me_devops_auto",
|
||||
action="store_true",
|
||||
help="Open application devops and show entry me and run auto setup.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--open_me_devops_auto_force",
|
||||
action="store_true",
|
||||
help=(
|
||||
"Open application devops and show entry me and run auto setup with"
|
||||
" forcing argument."
|
||||
),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--not_private_mode",
|
||||
action="store_true",
|
||||
help="Default is private mode.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--record_mode",
|
||||
action="store_true",
|
||||
help="Start recording (not finish to be implemented).",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--not_dark_mode",
|
||||
action="store_true",
|
||||
help=(
|
||||
"By default, will be in dark mode, because the main developer"
|
||||
" like it!"
|
||||
),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--url",
|
||||
default="http://127.0.0.1:8069",
|
||||
help="URL to open.",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
if args.open_me_devops_auto_force:
|
||||
args.open_me_devops_auto = True
|
||||
args.open_me_devops = True
|
||||
elif args.open_me_devops_auto:
|
||||
args.open_me_devops = True
|
||||
return args
|
||||
|
||||
|
||||
def click(driver, xpath, time=5):
|
||||
wait = WebDriverWait(driver, time)
|
||||
button = wait.until(
|
||||
EC.element_to_be_clickable(
|
||||
(
|
||||
By.XPATH,
|
||||
xpath,
|
||||
)
|
||||
)
|
||||
)
|
||||
button.click()
|
||||
|
||||
|
||||
def run(config):
|
||||
if config.record_mode:
|
||||
new_path = os.path.normpath(
|
||||
os.path.join(os.path.dirname(__file__), "..", "..")
|
||||
)
|
||||
sys.path.append(new_path)
|
||||
from script.selenium.selenium_video import VideoRecorder
|
||||
|
||||
# Configuration pour lancer Firefox en mode de navigation privée
|
||||
firefox_options = webdriver.FirefoxOptions()
|
||||
if not config.not_private_mode:
|
||||
firefox_options.add_argument("--private")
|
||||
|
||||
# Définissez la préférence pour les notifications de bureau
|
||||
# 1 signifie "autoriser", 2 signifie "bloquer"
|
||||
firefox_options.set_preference(
|
||||
"permissions.default.desktop-notification", 1
|
||||
)
|
||||
|
||||
# Remplissez le courriel et le mot de passe
|
||||
courriel_input.send_keys("admin")
|
||||
mot_de_passe_input.send_keys("admin")
|
||||
# Créez une instance du navigateur Firefox avec les options de navigation privée
|
||||
driver = webdriver.Firefox(options=firefox_options)
|
||||
|
||||
# Cliquez sur le bouton "Connexion"
|
||||
connexion_button.click()
|
||||
# Ajout de l'enregistrement
|
||||
if config.record_mode:
|
||||
video_recorder = VideoRecorder(driver)
|
||||
else:
|
||||
video_recorder = None
|
||||
|
||||
# Fermez le navigateur
|
||||
# driver.quit()
|
||||
# Install DarkReader to help my eyes
|
||||
# TODO do a script to check if it's the last version
|
||||
if not config.not_dark_mode:
|
||||
driver.install_addon(
|
||||
"./script/selenium/darkreader-firefox.xpi", temporary=True
|
||||
)
|
||||
driver.install_addon(
|
||||
"./script/selenium/odoo_debug-4.0.xpi", temporary=True
|
||||
)
|
||||
|
||||
if not config.not_private_mode and not config.not_dark_mode:
|
||||
driver.get("about:addons")
|
||||
# Enable Dark Reader into incognito
|
||||
click(driver, "/html/body/div/div[1]/categories-box/button[2]")
|
||||
click(
|
||||
driver,
|
||||
"/html/body/div/div[2]/div/addon-list/section[1]/addon-card/div/div/div/div/button",
|
||||
)
|
||||
click(
|
||||
driver,
|
||||
"/html/body/div/div[2]/div/addon-list/section[1]/addon-card/div/addon-options/panel-list/panel-item[5]",
|
||||
)
|
||||
click(
|
||||
driver,
|
||||
"/html/body/div/div[2]/div/addon-card/div/addon-details/named-deck/section/div[5]/div/label[1]/input",
|
||||
)
|
||||
|
||||
# Enable Odoo_debug into incognito
|
||||
# Back
|
||||
click(
|
||||
driver, "/html/body/div/div[2]/addon-page-header/div/div[2]/button"
|
||||
)
|
||||
click(
|
||||
driver,
|
||||
"/html/body/div/div[2]/div/addon-list/section[1]/addon-card[2]/div/div/div/div/button",
|
||||
)
|
||||
click(
|
||||
driver,
|
||||
"/html/body/div/div[2]/div/addon-list/section[1]/addon-card[2]/div/addon-options/panel-list/panel-item[5]",
|
||||
)
|
||||
click(
|
||||
driver,
|
||||
"/html/body/div/div[2]/div/addon-card/div/addon-details/named-deck/section/div[5]/div/label[1]/input",
|
||||
)
|
||||
|
||||
# Ouvrez la page web
|
||||
driver.get(f"{config.url}/web")
|
||||
|
||||
# Close tab opening by DarkReader
|
||||
if config.not_private_mode and not config.not_dark_mode:
|
||||
driver.switch_to.window(driver.window_handles[-1])
|
||||
driver.close()
|
||||
driver.switch_to.window(driver.window_handles[0])
|
||||
|
||||
# Démarrer l'enregistrement
|
||||
if config.record_mode:
|
||||
video_recorder.start()
|
||||
|
||||
# Trouvez les éléments du formulaire
|
||||
courriel_input = driver.find_element(By.NAME, "login")
|
||||
mot_de_passe_input = driver.find_element(By.NAME, "password")
|
||||
try:
|
||||
connexion_button = driver.find_element(
|
||||
By.XPATH,
|
||||
"/html/body/div/div/div/form/div[3]/button"
|
||||
# '//button[contains(text(), "Log in")]'
|
||||
)
|
||||
except Exception:
|
||||
connexion_button = driver.find_element(
|
||||
By.XPATH,
|
||||
"/html/body/div/main/div/form/div[3]/button"
|
||||
# '//button[contains(text(), "Connexion")]'
|
||||
)
|
||||
|
||||
# Remplissez le courriel et le mot de passe
|
||||
courriel_input.send_keys("admin")
|
||||
mot_de_passe_input.send_keys("admin")
|
||||
|
||||
# Cliquez sur le bouton "Connexion"
|
||||
connexion_button.click()
|
||||
|
||||
# Attendez que l'élément soit cliquable
|
||||
wait = WebDriverWait(driver, 5)
|
||||
# menu_toggle = wait.until(
|
||||
# EC.element_to_be_clickable((By.XPATH, "/html/body/header/nav/ul[1]/li/a"))
|
||||
# )
|
||||
#
|
||||
# # Cliquez sur l'élément
|
||||
# menu_toggle.click()
|
||||
#
|
||||
# # Attendez que le lien soit cliquable
|
||||
# menu_item = wait.until(
|
||||
# EC.element_to_be_clickable(
|
||||
# (
|
||||
# By.XPATH,
|
||||
# "/html/body/header/nav/ul[1]/li/div/a[2]",
|
||||
# )
|
||||
# )
|
||||
# )
|
||||
|
||||
# Open View
|
||||
if config.open_me_devops:
|
||||
click(
|
||||
driver,
|
||||
"/html/body/header/nav/div/div[1]/div[2]/div/div/div/ul/li[2]/a",
|
||||
)
|
||||
click(
|
||||
driver,
|
||||
"/html/body/div[1]/main/div[2]/div/div/table/tbody/tr[1]/td[2]",
|
||||
)
|
||||
if config.open_me_devops_auto:
|
||||
click(
|
||||
driver,
|
||||
"/html/body/header/nav/div/div[1]/div[2]/div/div/div/ul/li[2]/a",
|
||||
)
|
||||
click(
|
||||
driver,
|
||||
"/html/body/div[1]/main/div[2]/div/div/table/tbody/tr[1]/td[2]",
|
||||
)
|
||||
|
||||
# CG self
|
||||
# Bouton modifier
|
||||
click(
|
||||
driver,
|
||||
"/html/body/div[1]/main/div[1]/div[2]/div/div/div[1]/button[1]",
|
||||
)
|
||||
# Tab CG
|
||||
click(
|
||||
driver,
|
||||
"/html/body/div[1]/main/div[2]/div/div/div[7]/ul/li[3]/a",
|
||||
)
|
||||
if config.open_me_devops_auto_force:
|
||||
# Disable «Stop Execution if Env Not Clean
|
||||
click(
|
||||
driver,
|
||||
"/html/body/div[1]/main/div[2]/div/div/div[7]/div/div[3]/div[2]/table[2]/tbody/tr/td[1]/label",
|
||||
)
|
||||
# Gen
|
||||
click(
|
||||
driver,
|
||||
"/html/body/div[1]/main/div[2]/div/div/div[7]/div/div[3]/div[2]/table[1]/tbody/tr[2]/td[1]/button",
|
||||
)
|
||||
|
||||
# Check error
|
||||
click(
|
||||
driver,
|
||||
"/html/body/div[1]/main/div[2]/div/div/div[7]/ul/li[14]/a",
|
||||
)
|
||||
# click(driver, "/html/body/div[1]/main/div[2]/div/div/div[6]/div/div[14]/div/div[2]/table/tbody/tr[1]", time=60*2)
|
||||
|
||||
# Arrêter l'enregistrement
|
||||
if config.record_mode:
|
||||
video_recorder.stop()
|
||||
|
||||
# Open conversation chat
|
||||
# conversation_button = driver.find_element(By.XPATH, '/html/body/header/nav/ul[3]/li[2]/a')
|
||||
# conversation_button.click()
|
||||
|
||||
# Close bot chat
|
||||
# conversation_button = driver.find_element(By.XPATH, '/html/body/div[3]/div[1]/span[2]/a[2]')
|
||||
# conversation_button.click()
|
||||
|
||||
# Fermez le navigateur
|
||||
# driver.quit()
|
||||
|
||||
|
||||
def main():
|
||||
config = get_config()
|
||||
run(config)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
|
|
|
|||
|
|
@ -1,169 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
import os
|
||||
import sys
|
||||
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.support import expected_conditions as EC
|
||||
from selenium.webdriver.support.ui import WebDriverWait
|
||||
|
||||
private_mode = True
|
||||
record_mode = False
|
||||
dark_reader_mode = True
|
||||
|
||||
|
||||
def click(driver, xpath, time=5):
|
||||
wait = WebDriverWait(driver, time)
|
||||
button = wait.until(
|
||||
EC.element_to_be_clickable(
|
||||
(
|
||||
By.XPATH,
|
||||
xpath,
|
||||
)
|
||||
)
|
||||
)
|
||||
button.click()
|
||||
|
||||
|
||||
if record_mode:
|
||||
new_path = os.path.normpath(
|
||||
os.path.join(os.path.dirname(__file__), "..", "..")
|
||||
)
|
||||
sys.path.append(new_path)
|
||||
from script.selenium.selenium_video import VideoRecorder
|
||||
|
||||
# Configuration pour lancer Firefox en mode de navigation privée
|
||||
firefox_options = webdriver.FirefoxOptions()
|
||||
if private_mode:
|
||||
firefox_options.add_argument("--private")
|
||||
|
||||
# Définissez la préférence pour les notifications de bureau
|
||||
# 1 signifie "autoriser", 2 signifie "bloquer"
|
||||
firefox_options.set_preference("permissions.default.desktop-notification", 1)
|
||||
|
||||
# Créez une instance du navigateur Firefox avec les options de navigation privée
|
||||
driver = webdriver.Firefox(options=firefox_options)
|
||||
|
||||
# Ajout de l'enregistrement
|
||||
if record_mode:
|
||||
video_recorder = VideoRecorder(driver)
|
||||
else:
|
||||
video_recorder = None
|
||||
|
||||
# Install DarkReader to help my eyes
|
||||
# TODO do a script to check if it's the last version
|
||||
if dark_reader_mode:
|
||||
driver.install_addon(
|
||||
"./script/selenium/darkreader-firefox.xpi", temporary=True
|
||||
)
|
||||
driver.install_addon(
|
||||
"./script/selenium/odoo_debug-4.0.xpi", temporary=True
|
||||
)
|
||||
|
||||
if private_mode and dark_reader_mode:
|
||||
driver.get("about:addons")
|
||||
# Enable Dark Reader into incognito
|
||||
click(driver, "/html/body/div/div[1]/categories-box/button[2]")
|
||||
click(
|
||||
driver,
|
||||
"/html/body/div/div[2]/div/addon-list/section[1]/addon-card/div/div/div/div/button",
|
||||
)
|
||||
click(
|
||||
driver,
|
||||
"/html/body/div/div[2]/div/addon-list/section[1]/addon-card/div/addon-options/panel-list/panel-item[5]",
|
||||
)
|
||||
click(
|
||||
driver,
|
||||
"/html/body/div/div[2]/div/addon-card/div/addon-details/named-deck/section/div[5]/div/label[1]/input",
|
||||
)
|
||||
|
||||
# Enable Odoo_debug into incognito
|
||||
# Back
|
||||
click(driver, "/html/body/div/div[2]/addon-page-header/div/div[2]/button")
|
||||
click(
|
||||
driver,
|
||||
"/html/body/div/div[2]/div/addon-list/section[1]/addon-card[2]/div/div/div/div/button",
|
||||
)
|
||||
click(
|
||||
driver,
|
||||
"/html/body/div/div[2]/div/addon-list/section[1]/addon-card[2]/div/addon-options/panel-list/panel-item[5]",
|
||||
)
|
||||
click(
|
||||
driver,
|
||||
"/html/body/div/div[2]/div/addon-card/div/addon-details/named-deck/section/div[5]/div/label[1]/input",
|
||||
)
|
||||
|
||||
# Ouvrez la page web
|
||||
driver.get("http://127.0.0.1:8069/web")
|
||||
|
||||
# Close tab opening by DarkReader
|
||||
if not private_mode and dark_reader_mode:
|
||||
driver.switch_to.window(driver.window_handles[-1])
|
||||
driver.close()
|
||||
driver.switch_to.window(driver.window_handles[0])
|
||||
|
||||
# Démarrer l'enregistrement
|
||||
if record_mode:
|
||||
video_recorder.start()
|
||||
|
||||
# Trouvez les éléments du formulaire
|
||||
courriel_input = driver.find_element(By.NAME, "login")
|
||||
mot_de_passe_input = driver.find_element(By.NAME, "password")
|
||||
try:
|
||||
connexion_button = driver.find_element(
|
||||
By.XPATH,
|
||||
"/html/body/div/div/div/form/div[3]/button"
|
||||
# '//button[contains(text(), "Log in")]'
|
||||
)
|
||||
except Exception:
|
||||
connexion_button = driver.find_element(
|
||||
By.XPATH,
|
||||
"/html/body/div/main/div/form/div[3]/button"
|
||||
# '//button[contains(text(), "Connexion")]'
|
||||
)
|
||||
|
||||
# Remplissez le courriel et le mot de passe
|
||||
courriel_input.send_keys("admin")
|
||||
mot_de_passe_input.send_keys("admin")
|
||||
|
||||
# Cliquez sur le bouton "Connexion"
|
||||
connexion_button.click()
|
||||
|
||||
# Attendez que l'élément soit cliquable
|
||||
wait = WebDriverWait(driver, 5)
|
||||
# menu_toggle = wait.until(
|
||||
# EC.element_to_be_clickable((By.XPATH, "/html/body/header/nav/ul[1]/li/a"))
|
||||
# )
|
||||
#
|
||||
# # Cliquez sur l'élément
|
||||
# menu_toggle.click()
|
||||
#
|
||||
# # Attendez que le lien soit cliquable
|
||||
# menu_item = wait.until(
|
||||
# EC.element_to_be_clickable(
|
||||
# (
|
||||
# By.XPATH,
|
||||
# "/html/body/header/nav/ul[1]/li/div/a[2]",
|
||||
# )
|
||||
# )
|
||||
# )
|
||||
|
||||
# Open View
|
||||
click(driver, "/html/body/header/nav/div/div[1]/div[2]/div/div/div/ul/li[2]/a")
|
||||
click(driver, "/html/body/div[1]/main/div[2]/div/div/table/tbody/tr[1]/td[2]")
|
||||
|
||||
# Arrêter l'enregistrement
|
||||
if record_mode:
|
||||
video_recorder.stop()
|
||||
|
||||
# Open conversation chat
|
||||
# conversation_button = driver.find_element(By.XPATH, '/html/body/header/nav/ul[3]/li[2]/a')
|
||||
# conversation_button.click()
|
||||
|
||||
# Close bot chat
|
||||
# conversation_button = driver.find_element(By.XPATH, '/html/body/div[3]/div[1]/span[2]/a[2]')
|
||||
# conversation_button.click()
|
||||
|
||||
# Fermez le navigateur
|
||||
# driver.quit()
|
||||
|
|
@ -1,171 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
import os
|
||||
import sys
|
||||
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.support import expected_conditions as EC
|
||||
from selenium.webdriver.support.ui import WebDriverWait
|
||||
|
||||
private_mode = True
|
||||
record_mode = False
|
||||
dark_reader_mode = True
|
||||
|
||||
|
||||
def click(driver, xpath, time=5):
|
||||
wait = WebDriverWait(driver, time)
|
||||
button = wait.until(
|
||||
EC.element_to_be_clickable(
|
||||
(
|
||||
By.XPATH,
|
||||
xpath,
|
||||
)
|
||||
)
|
||||
)
|
||||
button.click()
|
||||
|
||||
|
||||
if record_mode:
|
||||
new_path = os.path.normpath(
|
||||
os.path.join(os.path.dirname(__file__), "..", "..")
|
||||
)
|
||||
sys.path.append(new_path)
|
||||
from script.selenium.selenium_video import VideoRecorder
|
||||
|
||||
# Configuration pour lancer Firefox en mode de navigation privée
|
||||
firefox_options = webdriver.FirefoxOptions()
|
||||
if private_mode:
|
||||
firefox_options.add_argument("--private")
|
||||
|
||||
# Définissez la préférence pour les notifications de bureau
|
||||
# 1 signifie "autoriser", 2 signifie "bloquer"
|
||||
firefox_options.set_preference("permissions.default.desktop-notification", 1)
|
||||
|
||||
# Créez une instance du navigateur Firefox avec les options de navigation privée
|
||||
driver = webdriver.Firefox(options=firefox_options)
|
||||
|
||||
# Ajout de l'enregistrement
|
||||
if record_mode:
|
||||
video_recorder = VideoRecorder(driver)
|
||||
else:
|
||||
video_recorder = None
|
||||
|
||||
# Install DarkReader to help my eyes
|
||||
# TODO do a script to check if it's the last version
|
||||
if dark_reader_mode:
|
||||
driver.install_addon(
|
||||
"./script/selenium/darkreader-firefox.xpi", temporary=True
|
||||
)
|
||||
driver.install_addon(
|
||||
"./script/selenium/odoo_debug-4.0.xpi", temporary=True
|
||||
)
|
||||
|
||||
if private_mode and dark_reader_mode:
|
||||
driver.get("about:addons")
|
||||
click(driver, "/html/body/div/div[1]/categories-box/button[2]")
|
||||
click(
|
||||
driver,
|
||||
"/html/body/div/div[2]/div/addon-list/section[1]/addon-card/div/div/div/div/button",
|
||||
)
|
||||
click(
|
||||
driver,
|
||||
"/html/body/div/div[2]/div/addon-list/section[1]/addon-card/div/addon-options/panel-list/panel-item[5]",
|
||||
)
|
||||
click(
|
||||
driver,
|
||||
"/html/body/div/div[2]/div/addon-card/div/addon-details/named-deck/section/div[5]/div/label[1]/input",
|
||||
)
|
||||
|
||||
# Enable Odoo_debug into incognito
|
||||
# Back
|
||||
click(driver, "/html/body/div/div[2]/addon-page-header/div/div[2]/button")
|
||||
click(
|
||||
driver,
|
||||
"/html/body/div/div[2]/div/addon-list/section[1]/addon-card[2]/div/div/div/div/button",
|
||||
)
|
||||
click(
|
||||
driver,
|
||||
"/html/body/div/div[2]/div/addon-list/section[1]/addon-card[2]/div/addon-options/panel-list/panel-item[5]",
|
||||
)
|
||||
click(
|
||||
driver,
|
||||
"/html/body/div/div[2]/div/addon-card/div/addon-details/named-deck/section/div[5]/div/label[1]/input",
|
||||
)
|
||||
|
||||
# Ouvrez la page web
|
||||
driver.get("http://127.0.0.1:8069/web")
|
||||
|
||||
# Close tab opening by DarkReader
|
||||
if not private_mode and dark_reader_mode:
|
||||
driver.switch_to.window(driver.window_handles[-1])
|
||||
driver.close()
|
||||
driver.switch_to.window(driver.window_handles[0])
|
||||
|
||||
# Démarrer l'enregistrement
|
||||
if record_mode:
|
||||
video_recorder.start()
|
||||
|
||||
# Trouvez les éléments du formulaire
|
||||
courriel_input = driver.find_element(By.NAME, "login")
|
||||
mot_de_passe_input = driver.find_element(By.NAME, "password")
|
||||
try:
|
||||
connexion_button = driver.find_element(
|
||||
By.XPATH,
|
||||
"/html/body/div/div/div/form/div[3]/button"
|
||||
# '//button[contains(text(), "Log in")]'
|
||||
)
|
||||
except Exception:
|
||||
connexion_button = driver.find_element(
|
||||
By.XPATH,
|
||||
"/html/body/div/main/div/form/div[3]/button"
|
||||
# '//button[contains(text(), "Connexion")]'
|
||||
)
|
||||
|
||||
# Remplissez le courriel et le mot de passe
|
||||
courriel_input.send_keys("admin")
|
||||
mot_de_passe_input.send_keys("admin")
|
||||
|
||||
# Cliquez sur le bouton "Connexion"
|
||||
connexion_button.click()
|
||||
|
||||
# Open View
|
||||
click(driver, "/html/body/header/nav/div/div[1]/div[2]/div/div/div/ul/li[2]/a")
|
||||
click(driver, "/html/body/div[1]/main/div[2]/div/div/table/tbody/tr[1]/td[2]")
|
||||
click(driver, "/html/body/header/nav/div/div[1]/div[2]/div/div/div/ul/li[2]/a")
|
||||
click(driver, "/html/body/div[1]/main/div[2]/div/div/table/tbody/tr[1]/td[2]")
|
||||
|
||||
# CG self
|
||||
# Bouton modifier
|
||||
click(driver, "/html/body/div[1]/main/div[1]/div[2]/div/div/div[1]/button[1]")
|
||||
# Tab CG
|
||||
click(driver, "/html/body/div[1]/main/div[2]/div/div/div[7]/ul/li[3]/a")
|
||||
# Disable «Stop Execution if Env Not Clean
|
||||
# click(
|
||||
# driver,
|
||||
# "/html/body/div[1]/main/div[2]/div/div/div[7]/div/div[3]/div[2]/table[2]/tbody/tr/td[1]/label",
|
||||
# )
|
||||
# Gen
|
||||
click(
|
||||
driver,
|
||||
"/html/body/div[1]/main/div[2]/div/div/div[7]/div/div[3]/div[2]/table[1]/tbody/tr[2]/td[1]/button",
|
||||
)
|
||||
|
||||
# Check error
|
||||
click(driver, "/html/body/div[1]/main/div[2]/div/div/div[7]/ul/li[14]/a")
|
||||
# click(driver, "/html/body/div[1]/main/div[2]/div/div/div[6]/div/div[14]/div/div[2]/table/tbody/tr[1]", time=60*2)
|
||||
|
||||
# Arrêter l'enregistrement
|
||||
if record_mode:
|
||||
video_recorder.stop()
|
||||
|
||||
# Open conversation chat
|
||||
# conversation_button = driver.find_element(By.XPATH, '/html/body/header/nav/ul[3]/li[2]/a')
|
||||
# conversation_button.click()
|
||||
|
||||
# Close bot chat
|
||||
# conversation_button = driver.find_element(By.XPATH, '/html/body/div[3]/div[1]/span[2]/a[2]')
|
||||
# conversation_button.click()
|
||||
|
||||
# Fermez le navigateur
|
||||
# driver.quit()
|
||||
|
|
@ -1,171 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
import os
|
||||
import sys
|
||||
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.support import expected_conditions as EC
|
||||
from selenium.webdriver.support.ui import WebDriverWait
|
||||
|
||||
private_mode = True
|
||||
record_mode = False
|
||||
dark_reader_mode = True
|
||||
|
||||
|
||||
def click(driver, xpath, time=5):
|
||||
wait = WebDriverWait(driver, time)
|
||||
button = wait.until(
|
||||
EC.element_to_be_clickable(
|
||||
(
|
||||
By.XPATH,
|
||||
xpath,
|
||||
)
|
||||
)
|
||||
)
|
||||
button.click()
|
||||
|
||||
|
||||
if record_mode:
|
||||
new_path = os.path.normpath(
|
||||
os.path.join(os.path.dirname(__file__), "..", "..")
|
||||
)
|
||||
sys.path.append(new_path)
|
||||
from script.selenium.selenium_video import VideoRecorder
|
||||
|
||||
# Configuration pour lancer Firefox en mode de navigation privée
|
||||
firefox_options = webdriver.FirefoxOptions()
|
||||
if private_mode:
|
||||
firefox_options.add_argument("--private")
|
||||
|
||||
# Définissez la préférence pour les notifications de bureau
|
||||
# 1 signifie "autoriser", 2 signifie "bloquer"
|
||||
firefox_options.set_preference("permissions.default.desktop-notification", 1)
|
||||
|
||||
# Créez une instance du navigateur Firefox avec les options de navigation privée
|
||||
driver = webdriver.Firefox(options=firefox_options)
|
||||
|
||||
# Ajout de l'enregistrement
|
||||
if record_mode:
|
||||
video_recorder = VideoRecorder(driver)
|
||||
else:
|
||||
video_recorder = None
|
||||
|
||||
# Install DarkReader to help my eyes
|
||||
# TODO do a script to check if it's the last version
|
||||
if dark_reader_mode:
|
||||
driver.install_addon(
|
||||
"./script/selenium/darkreader-firefox.xpi", temporary=True
|
||||
)
|
||||
driver.install_addon(
|
||||
"./script/selenium/odoo_debug-4.0.xpi", temporary=True
|
||||
)
|
||||
|
||||
if private_mode and dark_reader_mode:
|
||||
driver.get("about:addons")
|
||||
click(driver, "/html/body/div/div[1]/categories-box/button[2]")
|
||||
click(
|
||||
driver,
|
||||
"/html/body/div/div[2]/div/addon-list/section[1]/addon-card/div/div/div/div/button",
|
||||
)
|
||||
click(
|
||||
driver,
|
||||
"/html/body/div/div[2]/div/addon-list/section[1]/addon-card/div/addon-options/panel-list/panel-item[5]",
|
||||
)
|
||||
click(
|
||||
driver,
|
||||
"/html/body/div/div[2]/div/addon-card/div/addon-details/named-deck/section/div[5]/div/label[1]/input",
|
||||
)
|
||||
|
||||
# Enable Odoo_debug into incognito
|
||||
# Back
|
||||
click(driver, "/html/body/div/div[2]/addon-page-header/div/div[2]/button")
|
||||
click(
|
||||
driver,
|
||||
"/html/body/div/div[2]/div/addon-list/section[1]/addon-card[2]/div/div/div/div/button",
|
||||
)
|
||||
click(
|
||||
driver,
|
||||
"/html/body/div/div[2]/div/addon-list/section[1]/addon-card[2]/div/addon-options/panel-list/panel-item[5]",
|
||||
)
|
||||
click(
|
||||
driver,
|
||||
"/html/body/div/div[2]/div/addon-card/div/addon-details/named-deck/section/div[5]/div/label[1]/input",
|
||||
)
|
||||
|
||||
# Ouvrez la page web
|
||||
driver.get("http://127.0.0.1:8069/web")
|
||||
|
||||
# Close tab opening by DarkReader
|
||||
if not private_mode and dark_reader_mode:
|
||||
driver.switch_to.window(driver.window_handles[-1])
|
||||
driver.close()
|
||||
driver.switch_to.window(driver.window_handles[0])
|
||||
|
||||
# Démarrer l'enregistrement
|
||||
if record_mode:
|
||||
video_recorder.start()
|
||||
|
||||
# Trouvez les éléments du formulaire
|
||||
courriel_input = driver.find_element(By.NAME, "login")
|
||||
mot_de_passe_input = driver.find_element(By.NAME, "password")
|
||||
try:
|
||||
connexion_button = driver.find_element(
|
||||
By.XPATH,
|
||||
"/html/body/div/div/div/form/div[3]/button"
|
||||
# '//button[contains(text(), "Log in")]'
|
||||
)
|
||||
except Exception:
|
||||
connexion_button = driver.find_element(
|
||||
By.XPATH,
|
||||
"/html/body/div/main/div/form/div[3]/button"
|
||||
# '//button[contains(text(), "Connexion")]'
|
||||
)
|
||||
|
||||
# Remplissez le courriel et le mot de passe
|
||||
courriel_input.send_keys("admin")
|
||||
mot_de_passe_input.send_keys("admin")
|
||||
|
||||
# Cliquez sur le bouton "Connexion"
|
||||
connexion_button.click()
|
||||
|
||||
# Open View
|
||||
click(driver, "/html/body/header/nav/div/div[1]/div[2]/div/div/div/ul/li[2]/a")
|
||||
click(driver, "/html/body/div[1]/main/div[2]/div/div/table/tbody/tr[1]/td[2]")
|
||||
click(driver, "/html/body/header/nav/div/div[1]/div[2]/div/div/div/ul/li[2]/a")
|
||||
click(driver, "/html/body/div[1]/main/div[2]/div/div/table/tbody/tr[1]/td[2]")
|
||||
|
||||
# CG self
|
||||
# Bouton modifier
|
||||
click(driver, "/html/body/div[1]/main/div[1]/div[2]/div/div/div[1]/button[1]")
|
||||
# Tab CG
|
||||
click(driver, "/html/body/div[1]/main/div[2]/div/div/div[7]/ul/li[3]/a")
|
||||
# Disable «Stop Execution if Env Not Clean
|
||||
click(
|
||||
driver,
|
||||
"/html/body/div[1]/main/div[2]/div/div/div[7]/div/div[3]/div[2]/table[2]/tbody/tr/td[1]/label",
|
||||
)
|
||||
# Gen
|
||||
click(
|
||||
driver,
|
||||
"/html/body/div[1]/main/div[2]/div/div/div[7]/div/div[3]/div[2]/table[1]/tbody/tr[2]/td[1]/button",
|
||||
)
|
||||
|
||||
# Check error
|
||||
click(driver, "/html/body/div[1]/main/div[2]/div/div/div[7]/ul/li[14]/a")
|
||||
# click(driver, "/html/body/div[1]/main/div[2]/div/div/div[6]/div/div[14]/div/div[2]/table/tbody/tr[1]", time=60*2)
|
||||
|
||||
# Arrêter l'enregistrement
|
||||
if record_mode:
|
||||
video_recorder.stop()
|
||||
|
||||
# Open conversation chat
|
||||
# conversation_button = driver.find_element(By.XPATH, '/html/body/header/nav/ul[3]/li[2]/a')
|
||||
# conversation_button.click()
|
||||
|
||||
# Close bot chat
|
||||
# conversation_button = driver.find_element(By.XPATH, '/html/body/div[3]/div[1]/span[2]/a[2]')
|
||||
# conversation_button.click()
|
||||
|
||||
# Fermez le navigateur
|
||||
# driver.quit()
|
||||
Loading…
Reference in a new issue