FireEvent operation is used in LeanFT now known as UFT Developer to perform events like mouseover, Keypress, and Keyup, etc on Web element using EventInfoFactory class in LeanFT (UFT Developer).
The following example illustrates how to use a fire event in LeanFT. The below code will navigate to Amazom.com.After that it will do a mouse over on the link “Hello, Sign in“.
On doing a mouseover, a mega menu is displayed.
After performing the mouse over the script will find the “Your Account” link and will perform a click action on it.
Example-Fire Event in LeanFT | UFT Developer
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 |
import org.testng.annotations.*; import com.hp.lft.report.ReportException; import com.hp.lft.report.Reporter; import com.hp.lft.report.Status; import com.hp.lft.sdk.GeneralLeanFtException; import com.hp.lft.sdk.web.Browser; import com.hp.lft.sdk.web.BrowserFactory; import com.hp.lft.sdk.web.BrowserType; import com.hp.lft.sdk.web.EventInfoFactory; import com.hp.lft.sdk.web.WebElement; import com.hp.lft.sdk.web.WebElementDescription; import unittesting.UnitTestClassBase; public class TestFireEvent extends UnitTestClassBase { Browser browser; @Test public void test() throws GeneralLeanFtException, CloneNotSupportedException, ReportException { //Opening Browser in Chrome browser = BrowserFactory.launch(BrowserType.CHROME); try { //Navigating to Amazon.com.Make sure you are not already login else the test will fail browser.navigate("https://www.amazon.com/"); WebElement helloSignInWebElement = browser.describe(WebElement.class, new WebElementDescription.Builder() .innerText("Hello, Sign in") .tagName("SPAN").build()); //***Performing FireEvent Operation**** helloSignInWebElement.fireEvent(EventInfoFactory.createEventInfo("mouseover")); WebElement yourAccountWebElement = browser.describe(WebElement.class, new WebElementDescription.Builder() .innerText("Your Account") .tagName("SPAN").build()); yourAccountWebElement.click(); } catch(AssertionError ex){ Reporter.reportEvent("Exception Occured","Test Failed", Status.Failed, ex); throw ex; } finally { //Close the browser Instance browser.close(); } } } |
You can find the following commonly used Events.
Event Name | Description |
click | The event occurs when the user clicks on an element |
dblclick | The event occurs when the user double-clicks on an element |
Keydown | The event occurs when the user is pressing a key |
Keypress | The event occurs when the user presses a key |
Keyup | The event occurs when the user releases a key |
Mouseenter | The event occurs when the pointer is moved onto an element |
Mouseleave | The event occurs when the pointer is moved out of an element |
Mousemove | The event occurs when the pointer is moving while it is over an element |
Mouseover | The event occurs when the pointer is moved onto an element, or onto one of its children |
Mouseout | The event occurs when a user moves the mouse pointer out of an element, or out of one of its children |
Recommended Posts
- Create Application Model Project in LeanFT | UFT Developer & Write First Test in Java
- How to Send Keystrokes In LeanFT | UFT Developer
- Create a UFT Developer | LeanFT Testing Project & Write Your First Test
- Intuitive Way of MySQL Database Testing in Selenium | LeanFT
- Read and Write Excel File in Java Using Apache POI Lib