java - Control Test Execution Progress with Keyboard Interrupts - using WebDriverEventListener & EventFiringWebDriver -
i have tests automated webdriver+java+testng+maven
i looking solution wherein progress (step next step) of test can controlled using keyboard interrupts on every navigation.
ex: lets automation navigation of application. progress of test should driven key press every page redirection.
i have partially found solution. used code github - https://gist.github.com/krmahadevan/1728633
test class -
import com.shn.library.webdriverlistener; public class dummytest { @test public void testmethod(){ webdriver driver = new firefoxdriver(); eventfiringwebdriver efwd = new eventfiringwebdriver(driver); webdriverlistener eventlistener = new webdriverlistener(efwd); efwd.register(eventlistener); efwd.get("http://www.yahoo.com"); efwd.get("https://www.mail.google.com"); } }
implementing webdrivereventlistener -
package com.shn.library; import java.awt.keyeventdispatcher; import java.awt.keyboardfocusmanager; import java.awt.event.keyevent; import java.util.concurrent.countdownlatch; import org.openqa.selenium.by; import org.openqa.selenium.webdriver; import org.openqa.selenium.webelement; import org.openqa.selenium.support.events.webdrivereventlistener; public class webdriverlistener implements webdrivereventlistener { private webdriver webdriver; public webdriverlistener(webdriver webdriver){ this.webdriver = webdriver; } public void beforenavigateto(string url, webdriver driver) { } public void afternavigateto(string url, webdriver driver) { final countdownlatch latch = new countdownlatch(1); keyeventdispatcher dispatcher = new keyeventdispatcher() { // anonymous class invoked edt public boolean dispatchkeyevent(keyevent e) { if (e.getkeycode() == keyevent.vk_space) latch.countdown(); return false; } }; keyboardfocusmanager.getcurrentkeyboardfocusmanager().addkeyeventdispatcher(dispatcher); try { latch.await(); } catch (interruptedexception e1) { // todo auto-generated catch block e1.printstacktrace(); } // current thread waits here until countdown() called keyboardfocusmanager.getcurrentkeyboardfocusmanager().removekeyeventdispatcher(dispatcher); system.out.println(this.webdriver.gettitle()); // todo auto-generated method stub } }
but then, getting infinite loop. key press (space) not being detected
i'm pretty sure want achieve cannot directly supported selenium. can share did 1 of our projects.,we used python simulate keyboard input android devices.
however, write wrapper code in python waits keyboard input , s executes selenium code.
more info in answer how simulate keyboard input which easiest way simulate keyboard , mouse on python?
Comments
Post a Comment