python : parametres de script (bash)
Bonjour à tous,
Je comprend pas un truc avec le passage de paramètres en Python. Voici mon problème :
Je n'arrive pas à faire passer 1 paramètre bash dans mon script python :
Code:
python monscript.py tintin
Dans mon script je tente de récupérer mon paramètre en procédant comme cela :
Code:
1 2 3
| for arg in sys.argv:
print arg
#~ myArg = sys.argv[0] |
Tout va bien, je n'ai pas de problème sauf quand mon script python contient une classe !
MACRO _SELENIUM
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
# -*- coding: utf-8 -*-
#~ from sys import argv
import sys, unittest, time, re
from selenium import webdriver
from selenium.webdriver import Firefox
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.support import expected_conditions as expected
from selenium.webdriver.support.wait import WebDriverWait
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
for arg in sys.argv:
print arg
#~ myArg = sys.argv[0]
class CONNEXION(unittest.TestCase):
def setUp(self):
#~ self.arg1 = sys.argv[0]
options = Options()
options.add_argument('-headless')
self.driver = webdriver.Firefox(firefox_options=options)
self.driver.implicitly_wait(30)
self.base_url = "https://tintin.fr/"
self.verificationErrors = []
self.accept_next_alert = True
def test_c_o_n_n_e_x_i_o_n(self):
driver = self.driver
driver.get(self.base_url + "/login")
driver.find_element_by_id("login").clear()
driver.find_element_by_id("login").send_keys("milou")
driver.find_element_by_id("mdp").clear()
driver.find_element_by_id("mdp").send_keys("osALaM@elle")
driver.find_element_by_id("submit").click()
s = driver.find_element_by_id("PGHeader").text
#~ if s.find("Sur la lune") == -1:
if s.find(sys.argv[1]) == -1:
#~ if s.find("TintinEtMilou") == -1:
print "chaine de controle absente"
print "ERREUR 30 : exit !"
sys.exit()
else:
print "chaine de controle presente"
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.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main() |
Avec cette macro selenium appelée comme ceci, j'ai le droit a une superbe erreur :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
stefane@vmselenium:~/Documents/selenium/TINTIN_AU_TIBET$ python CONNEXION.py tintin
CONNEXION.py
tintin
Traceback (most recent call last):
File "CONNEXION.py", line 75, in <module>
unittest.main()
File "/usr/lib/python2.7/unittest/main.py", line 94, in __init__
self.parseArgs(argv)
File "/usr/lib/python2.7/unittest/main.py", line 149, in parseArgs
self.createTests()
File "/usr/lib/python2.7/unittest/main.py", line 158, in createTests
self.module)
File "/usr/lib/python2.7/unittest/loader.py", line 130, in loadTestsFromNames
suites = [self.loadTestsFromName(name, module) for name in names]
File "/usr/lib/python2.7/unittest/loader.py", line 100, in loadTestsFromName
parent, obj = obj, getattr(obj, part)
AttributeError: 'module' object has no attribute 'tintin' |
Je suis bien embêté, d'habitude mon (pas trop) pote google m'aiguille toujours; mais là je suis coincé. Il y a comme un truc que j'ai pas compris... :(
Quelqu'un pour m'aider ?
A+++