CENTREON – Script pour sélénium pour controler que l’accèe internet

Voici un script en python à planifier avec Centreon pour contrôler de manière récurrente que l’accès internet fonction

Celui-ci est utilisable avec la version Docker Selenium-debug

Nom du script : GoogleSearch.py

#!/usr/bin/python # -*- coding: utf-8 -*- from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys from selenium.webdriver.support.ui import Select from selenium.common.exceptions import NoSuchElementException from selenium.common.exceptions import NoAlertPresentException import unittest, time, re class GoogleSearch(unittest.TestCase): def setUp(self): self.verificationErrors = [] self.driver = webdriver.Remote("http://10.200.10.146:5555/wd/hub", webdriver.DesiredCapabilities.FIREFOX.copy()) self.driver.implicitly_wait(30) self.base_url = "http://www.google.fr" self.accept_next_alert = True def test_py13(self): driver = self.driver # Ouvre la page de recherche google | /?gws_rd=ssl | driver.get(self.base_url + "/?gws_rd=ssl") # clique dans la zone de recherche | id=lst-ib | driver.find_element_by_id("lst-ib").click() # Saisie le texte a rechercher | id=lst-ib | centreon driver.find_element_by_id("lst-ib").clear() driver.find_element_by_id("lst-ib").send_keys("centreon") # click | css=#lga > div | driver.find_element_by_css_selector("#lga > div").click() # clique sur le bouton rechercher | name=btnK | driver.find_element_by_name("btnK").click() # clique sur le lien centreon | link=Centreon | driver.find_element_by_link_text("Centreon").click() # click | link=Logout | driver.find_element_by_link_text("Logout").click() # close | | driver.close() def is_element_present(self, how, what): try: self.driver.find_element(by=how, value=what) except NoSuchElementException as e: return False return True def is_alert_present(self): try: self.driver.switch_to_alert() except NoAlertPresentException as e: return False return True def close_alert_and_get_its_text(self): try: alert = self.driver.switch_to_alert() alert_text = alert.text if self.accept_next_alert: alert.accept() else: alert.dismiss() return alert_text finally: self.accept_next_alert = True #def tearDown(self): # self.driver.quit() self.selenium.stop() self.assertEqual([], self.verificationErrors) if __name__ == "__main__": unittest.main()

Ne pas oublier de faire la commande pour rendre le script exécutable

chmod +x GoogleSearch.py
Taggé , , , , , , , , , .Mettre en favori le Permaliens.

Les commentaires sont fermés.