Best SeLion code snippet using com.paypal.selion.platform.html.support.events.ElementListenerTestImpl
Source:ElementEventTest.java
...28 Grid.open("about:blank");29 String script = getScript();30 Grid.driver().executeScript(script);31 Thread.sleep(4000);32 Grid.getTestSession().getElementEventListeners().add(new ElementListenerTestImpl());33 TestPage page = new TestPage("US");34 page.clickContinueButton(page);35 Assert.assertEquals(page.getLogLabel().getProperty("data-before-click"), "true",36 "beforeClick method was not triggered.");37 Assert.assertEquals(page.getLogLabel().getProperty("data-after-click"), "true",38 "afterClick method was not triggered.");39 }40 @Test(groups = { "functional" })41 @WebTest42 public void testHoverEvents() throws InterruptedException, IOException {43 Grid.open("about:blank");44 String script = getScript();45 Grid.driver().executeScript(script);46 Thread.sleep(4000);47 Grid.getTestSession().getElementEventListeners().add(new ElementListenerTestImpl());48 TestPage page = new TestPage("US");49 page.getContinueButton().hover();50 Assert.assertEquals(page.getLogLabel().getProperty("data-before-hover"), "true",51 "beforeHover method was not triggered.");52 Assert.assertEquals(page.getLogLabel().getProperty("data-after-hover"), "true",53 "afterHover method was not triggered.");54 }55 @Test(groups = { "functional" })56 @WebTest57 public void testTypeEvents() throws InterruptedException, IOException {58 Grid.open("about:blank");59 String script = getScript();60 Grid.driver().executeScript(script);61 Thread.sleep(4000);62 Grid.getTestSession().getElementEventListeners().add(new ElementListenerTestImpl());63 TestPage page = new TestPage("US");64 page.setFieldXTextFieldValue("Test");65 Assert.assertEquals(page.getLogLabel().getProperty("data-before-type"), "true",66 "beforeType method was not triggered.");67 Assert.assertEquals(page.getLogLabel().getProperty("data-after-type"), "true",68 "afterType method was not triggered.");69 }70 @Test(groups = { "functional" })71 @WebTest72 public void testSelectEvents() throws InterruptedException, IOException {73 Grid.open("about:blank");74 String script = getScript();75 Grid.driver().executeScript(script);76 Thread.sleep(4000);77 Grid.getTestSession().getElementEventListeners().add(new ElementListenerTestImpl());78 TestPage page = new TestPage("US");79 page.getXSelectList().selectByIndex(1);80 page.getXSelectList().deselectByIndex(1);81 Assert.assertEquals(page.getLogLabel().getProperty("data-before-select"), "true",82 "beforeSelect method was not triggered.");83 Assert.assertEquals(page.getLogLabel().getProperty("data-after-select"), "true",84 "afterSelect method was not triggered.");85 Assert.assertEquals(page.getLogLabel().getProperty("data-before-deselect"), "true",86 "beforeDeselect method was not triggered.");87 Assert.assertEquals(page.getLogLabel().getProperty("data-after-deselect"), "true",88 "afterDeselect method was not triggered.");89 }90 @Test(groups = { "functional" })91 @WebTest92 public void testCheckEvents() throws InterruptedException, IOException {93 Grid.open("about:blank");94 String script = getScript();95 Grid.driver().executeScript(script);96 Thread.sleep(4000);97 Grid.getTestSession().getElementEventListeners().add(new ElementListenerTestImpl());98 TestPage page = new TestPage("US");99 page.getXCheckBox().check();100 page.getXCheckBox().uncheck();101 Assert.assertEquals(page.getLogLabel().getProperty("data-before-check"), "true",102 "beforeCheck method was not triggered.");103 Assert.assertEquals(page.getLogLabel().getProperty("data-after-check"), "true",104 "afterCheck method was not triggered.");105 Assert.assertEquals(page.getLogLabel().getProperty("data-before-uncheck"), "true",106 "beforeUncheck method was not triggered.");107 Assert.assertEquals(page.getLogLabel().getProperty("data-after-uncheck"), "true",108 "afterUncheck method was not triggered.");109 // Reset the events triggered for RadioButton testing110 page.getLogLabel().setProperty("data-before-check", null);111 page.getLogLabel().setProperty("data-after-check", null);...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!