@@ -77,50 +77,55 @@ driver.execute_script('lambdatest_executor:{"action":"lambda-heal-stop"}')
7777
7878``` python  title="Test.py"
7979import  os
80+ import  sys
8081import  time
82+ 
8183from  selenium import  webdriver
8284
83- platform =  os.getenv(' HYPEREXECUTE_PLATFORM'  )
85+ LT_USERNAME  =  os.getenv(' LT_USERNAME'  )
86+ LT_ACCESS_KEY  =  os.getenv(' LT_ACCESS_KEY'  )
8487
8588desired_cap_chrome =  {
86-  " build"  : " Lambdatest Build 2"  ,
87-  " name"  : " Lambdatest  Test"  ,
88-  " platform" : platform ,
89-  " browserName"  : " Chrome"  ,
90-  " version"  : " latest"  ,
91-  " visual"  : False ,
92-  " video"  : True ,
89+  " build"   : " Lambdatest Build 2"  ,
90+  " name"   : " Autoheal  Test via Hooks "  ,
91+  " platform"  :  " Windows 10 "  ,
92+  " browserName"   : " Chrome"  ,
93+  " version"   : " latest"  ,
94+  " visual"   : False ,
95+  " video"   : True ,
9396 " network"  : True ,
9497 " console"  : True ,
9598 ' goog:chromeOptions'  : {' args'  : [' --window-size=400x300'  ]},
9699}
97100
98- hub =  f " https:// { os.getenv( ' LT_USERNAME' ) } : { os.getenv( ' LT_ACCESS_KEY' ) } @hub.lambdatest.com/wd/hub " 
101+ hub =  f " https:// { LT_USERNAME } : { LT_ACCESS_KEY } @hub.lambdatest.com/wd/hub " 
99102
100- def  test_autoheal (caps , sleep_time = 5 ):
103+ def  OneTest (caps , sleepTime ):
104+     begin =  time.time()
101105    driver =  webdriver.Remote(command_executor = hub, desired_capabilities = caps)
102-     
103-     #  Navigate to page 
106+     end  =  time.time() 
107+     print ( f " Startup time for  { caps[ ' browserName ' ] }   { end  -  begin }  ,  { begin }  ,  { end } " ) 
104108    driver.get(" https://www.selenium.dev"  )
105-     
106-     #  ===== Autoheal START =====
107-     driver.execute_script(' lambdatest_executor:{"action":"lambda-heal-start"}'  )
108-     
109-     #  Interact with elements that may change dynamically
109+     time.sleep(sleepTime)
110+ 
111+     driver.execute_script(' lambdatest_executor:{"action":"lambda-heal-start"}'  ) # start hook for autoheal
112+ 
110113    driver.find_element_by_id(' td-block-1'  )
111-     driver.execute_script(' document.getElementById("td-block-1").id="updatedtd-block-1"; '  )
114+     driver.execute_script(" document.getElementById(\ " td-block-1\ " ).id=\ " updatedtd-block-1\" ; "  )
112115    driver.find_element_by_id(' updatedtd-block-1'  )
116+     driver.find_element_by_id(" td-block-1"  )
117+ 
118+     driver.execute_script(' lambdatest_executor:{"action":"lambda-heal-stop"}'  )  # stop hook for autoheal
113119
114-     #  ===== Autoheal STOP =====
115-     driver.execute_script(' lambdatest_executor:{"action":"lambda-heal-stop"}'  )
116-     
117-     #  Continue normal test steps
120+     driver.execute_script(" console.log('Test started');"  )
121+     driver.execute_script(" console.info('Navigated to selenium.dev');"  )
122+     driver.execute_script(" console.warn('This is a warning message');"  )
123+     driver.execute_script(" console.error('This is an error message');"  )
124+     driver.execute_script(" console.debug('Debugging test flow');"  )
118125    driver.execute_script(" console.log('Test completed successfully');"  )
119-     driver.execute_script(" lambda-status=passed"  )
120-     
121126    driver.quit()
122127
123- test_autoheal (desired_cap_chrome)
128+ OneTest (desired_cap_chrome,  5 )
124129``` 
125130
126131With these steps, you can seamlessly integrate LambdaTest HyperExecute Autoheal into your Selenium tests, reducing flaky tests and improving stability.
0 commit comments