@@ -45,23 +45,23 @@ def main(timeout_conn, interval, product_family, ref_product, ref_zones, quantit
4545 url_availability = "https://ws.ovh.com/dedicated/r2/ws.dispatcher/getAvailability2"
4646 not_available_terms = ['unknown' , 'unavailable' ]
4747
48- time_run = datetime . now (). strftime ( "%y-%m-%d %H-%M-%f" )
49-
50- screenshot_dir = os . getenv ( "SCREENSHOT_DIR" , os . path .abspath ( "screens" ))
51- log_dir = os .getenv ("LOG_DIR " , os . getcwd () )
48+ script_dir = os . path . dirname ( os . path . realpath ( __file__ ) )
49+ # Get env var if any, or the script directory as a fallback
50+ # Then in any case the "screens" folder to the path.
51+ screenshot_dir = os .path . join ( os . getenv ("SCREENSHOT_DIR " , script_dir ), "screens" )
5252 if not os .path .exists (screenshot_dir ):
5353 os .makedirs (screenshot_dir )
54+ print ("Saving screenshots in {}" .format (screenshot_dir ))
55+
56+ # Logs configuration
57+ log_dir = os .getenv ("LOG_DIR" , script_dir )
5458 if not os .path .exists (log_dir ):
5559 os .makedirs (log_dir )
5660 log_filename = os .path .join (log_dir , "buyKim.log" )
57-
5861 print ("Log filename: {}" .format (log_filename ))
5962 logging .basicConfig (format = '%(asctime)s - %(levelname)s - %(message)s' , filename = log_filename , level = logging .DEBUG )
6063 logging .getLogger ("requests" ).setLevel (logging .WARNING )
6164
62- print_and_log ("Saving screenshots in {}" .format (screenshot_dir ))
63- screen_prefix = screenshot_dir + time_run
64-
6565 available = False
6666 while not available :
6767 success = False
@@ -184,9 +184,9 @@ def main(timeout_conn, interval, product_family, ref_product, ref_zones, quantit
184184 button_existing .click ()
185185 print_and_log ("Clicked on existing customer." )
186186
187- screenshot_step (driver , screen_prefix , 1 )
187+ screenshot_step (driver , screenshot_dir , 1 )
188188 driver .execute_script ("arguments[0].scrollIntoView(true);" , button_existing )
189- screenshot_step (driver , screen_prefix , 2 )
189+ screenshot_step (driver , screenshot_dir , 2 )
190190 # Locate login inputs
191191 input_login = driver .find_element_by_id (id_input_login )
192192 input_pass = driver .find_element_by_id (id_input_pass )
@@ -198,7 +198,7 @@ def main(timeout_conn, interval, product_family, ref_product, ref_zones, quantit
198198 driver .find_element_by_css_selector (css_button_login ).click ()
199199 print_and_log ("Clicked on login button." )
200200
201- screenshot_step (driver , screen_prefix , 3 )
201+ screenshot_step (driver , screenshot_dir , 3 )
202202
203203 # Wait for means of payment to load
204204 css_payment_valid = "div.payment-means-choice div.payment-means-list form span.selected input.custom-radio.ng-valid"
@@ -213,14 +213,14 @@ def main(timeout_conn, interval, product_family, ref_product, ref_zones, quantit
213213
214214 # uncommented after numerous tests
215215 if not debug :
216- css_button_purchase = ".zone-content section:last button.centered"
216+ css_button_purchase = "div .zone-content div.dedicated-contracts button.centered"
217217 driver .find_element_by_css_selector (css_button_purchase ).click ()
218218 print_and_log ("Clicked on purchase button..." )
219219
220220 # Wait to realise what you've done
221- screenshot_step (driver , screen_prefix , 4 )
221+ screenshot_step (driver , screenshot_dir , 4 )
222222 time .sleep (30 )
223- screenshot_step (driver , screen_prefix , 5 )
223+ screenshot_step (driver , screenshot_dir , 5 )
224224 driver .close ()
225225
226226
0 commit comments