LeanFT now known as UFT Developer is loaded with lots of features and has been specially designed for continuous integration and continuous testing. It has a very strong mechanism to identify test objects. Having that said, sometimes we come across some weird situations wherein the inbuilt features of the tool don’t help us, and to figure it out we have to look for a workaround. One such strange scenario could be like clicking on a submit button, post-submission action is not being performed. Here we will take a look at such a few scenarios and learn how to resolve them.
In real-life automation scenarios sometimes we come across such objects on which if you perform a click operation it does not work. This is not just the case with buttons. In my automation career, I have also seen list boxes on which the automation tool is not able to select any item even though it is able to identify the list box. In such a tricky situation we need to simulate a human-like keypress or send keystrokes if the LeanFT is not able to click on a button or select an item from a list box, etc.
If you have also come across such a situation wherein you need to send keystrokes in LeanFT, you can use the following example. In this example, we will set the value in the first and last name field in a form of w3school. The link for that is mentioned in the code. After that, we will press the ENTER key rather than clicking on the submit button.
Example-Send Keystrokes 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 |
import org.testng.annotations.Test; import com.commonMethods.CommonMethods; import com.hp.lft.report.ReportException; import com.hp.lft.sdk.*; import com.hp.lft.sdk.Keyboard.Keys; 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.Button; import com.hp.lft.sdk.web.ButtonDescription; import com.hp.lft.sdk.web.EditField; import com.hp.lft.sdk.web.EditFieldDescription; import com.hp.lft.sdk.web.Frame; import com.hp.lft.sdk.web.FrameDescription; import unittesting.*; public class LeanFTSendkeystrokes extends UnitTestClassBase { Browser browser; @Test public void test() throws GeneralLeanFtException, ReportException { browser = BrowserFactory.launch(BrowserType.CHROME); browser.navigate("https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_button_form"); browser.sync(); EditField fnameEditField = browser.describe(Frame.class, new FrameDescription.Builder() .name("iframeResult").build()) .describe(EditField.class, new EditFieldDescription.Builder() .name("fname") .tagName("INPUT") .type("text").build()); fnameEditField.setValue("FirstName123"); EditField lnameEditField = browser.describe(Frame.class, new FrameDescription.Builder() .name("iframeResult").build()) .describe(EditField.class, new EditFieldDescription.Builder() .name("lname") .tagName("INPUT") .type("text").build()); lnameEditField.setValue("LastName123"); // Use the Mouse class to click on the last name field before sending Enter Key java.awt.Point abs = lnameEditField.getAbsoluteLocation(); java.awt.Point p = new java.awt.Point(abs.x + 5, abs.y + 5); Mouse.click(p); //Sending Enter Key Keyboard.pressKey(Keys.ENTER); } } |
Code Explanation
After entering values for first and last name the Enter key is being pressed instead of using the click() method.
Recommended Posts
- How to Automate a new Tab in LeanFT | UFT Developer
- UFT Developer | LeanFT Get Table Cell Values for all Rows of a Column
- Spy Multiple Objects in LeanFT Using Object Identification Center | OIC
- Read and Write Excel File in Java Using Apache POI Lib
- Intuitive Way of MySQL Database Testing in Selenium | LeanFT