Bonjour à toutes et tous,

Je découvre Python afin de créer des tests avec les webdrivers selenium...

Tout fonctionne correctement si je laisse tout mon test dans une seule procédure, => un seul cas test.
Par contre, si je fais plusieurs cas de test, le browser se coupe à la fin du premier et un nouveau browser est ouvert pour le deuxième cas de test
=> il est impossible de continuer mon test, je dois à nouveau me loguer dans l'application et revenir à la bonne page pour continuer le test ...

Ne serait-il pas possible que tous mes tests fonctionnent sur la même instance du browser ? Si oui, comment svp ?

Donc, dans l'exemple ci-dessous, j'aimerais qu'après le Test_001(qui est le login) le Test_002 se poursuive dans le même browser.
Pour le moment, le browser se ferme à la fin du Test_001, et un nouveau browser s'ouvre sur une page blanche ...

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keysfrom selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
import unittest, time, re
 
ENV = "ac1"
LOGIN = "henri"
PSWD = "123456"
 
class Jour01(unittest.TestCase):
    def setUp(self):
        global driver
        self.driver = webdriver.Chrome("C:\Selenium\chromedriver.exe")
        self.driver.implicitly_wait(60)
        self.base_url = "http://app-ac2.net/"
        self.verificationErrors = []
        self.accept_next_alert = True
 
    def Test_001(self):
        driver=self.driver
        driver.maximize_window
        self.driver.get("http://app-" + ENV + ".net/initApplication.do")
 
        driver.find_element_by_id("userId").clear()
        driver.find_element_by_id("userId").send_keys(LOGIN)
        driver.find_element_by_id("password").clear()
        driver.find_element_by_id("password").send_keys(PSWD)
        driver.find_element_by_css_selector("input.btnSmall").click()
 
    def Test_002(self):		
        driver.find_element_by_link_text("Contacts").click()
 
        driver.find_element_by_xpath("//*[@id='zoom']/div[3]/div[1]/ul/li[div//span[@title='Belgique']]/div/i").click()
        for i in range(60):
            try:
                if u"RÉGIONS" == driver.find_element_by_css_selector("div.zoom-header.ng-binding").text: break
            except: pass
            time.sleep(1)
        else: self.fail("time out")
 
## (...)
 
 
    def is_element_present(self, how, what):
        try: self.driver.find_element(by=how, value=what)
        except NoSuchElementException, e: return False
        return True
 
    def is_alert_present(self):
        try: self.driver.switch_to_alert()
        except NoAlertPresentException, 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()