""" Quick test script for the bulk import job acceptance automation. This script demonstrates how to use the automation with minimal setup. """ from provider.selenium_flow import start_firefox_resilient, ensure_logged_in, accept_bulk_import_jobs from config import PARTDB_BASE, UI_LANG_PATH def test_accept_jobs(): """ Test the accept_bulk_import_jobs function. This will open a browser, log you in, and let you manually navigate to the import jobs page before starting automation. """ print("=" * 70) print("BULK IMPORT JOB ACCEPTANCE - TEST MODE") print("=" * 70) print() print("This will:") print("1. Open a Firefox browser") print("2. Log you in to PartDB") print("3. Wait for you to navigate to the import jobs page") print("4. Start automating the acceptance of jobs") print() print("-" * 70) # Start browser print("Starting browser...") driver = start_firefox_resilient(headless_first=False) try: # Navigate and login print("Navigating to PartDB...") driver.get(PARTDB_BASE + "/") print("Logging in...") if not ensure_logged_in(driver, PARTDB_BASE, interactive_ok=True, wait_s=600): print("ERROR: Could not log in. Exiting.") return print("✓ Login successful!") print() # Wait for user to navigate print("=" * 70) print("READY TO START") print("=" * 70) print() print("Please navigate to your import jobs page in the browser.") print("The URL should look something like:") print(" https://partdb.../en/import/jobs/...") print() print("When you're on the page with 'Update part' buttons,") input("press ENTER to start automation... ") print() # Run automation print("Starting automation...") print("=" * 70) successful, failed, skipped = accept_bulk_import_jobs( driver, PARTDB_BASE, UI_LANG_PATH, job_url=None, # User already navigated max_iterations=100 ) # Results print() print("=" * 70) print("AUTOMATION COMPLETE") print("=" * 70) print(f"✓ Successfully processed: {successful} jobs") print(f"✗ Failed: {failed} jobs") print(f"⊘ Skipped (no results): {skipped} jobs") print("=" * 70) print() # Keep browser open print("Browser will remain open for inspection.") input("Press ENTER to close and exit... ") except KeyboardInterrupt: print("\n\nInterrupted by user.") except Exception as e: print(f"\n\nERROR: {e}") import traceback traceback.print_exc() input("\nPress ENTER to close... ") finally: try: driver.quit() print("Browser closed.") except Exception: pass if __name__ == "__main__": test_accept_jobs()