Saturday, January 7, 2023

SeleniumUtil 0.7.0 is now available with a few Java Script utility methods

Abstraction helps to promote code reuse and reduce development time among other benefits. When considering Selenium based test automation, you can abstract at many different points such as at dependency, infrastructure, technology, page, component or even at the element or locator level. SeleniumUtil is an open source library that aims to provide generic abstractions and other useful utilities so that you don’t need to worry about them in your Selenium based test automation projects.

Version 0.7.0 is now available in maven central and it provides a few technology level abstractions in the form of a few parameterized Java Script methods.


Usage


package com.dumiduh.other;
import com.dumiduh.constants.Constants;
import com.dumiduh.utils.TestBase;
import io.github.handakumbura.EventListener;
import io.github.handakumbura.JavaScriptHelper;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class JavaScriptHelper extends TestBase {
private static final String OPTIONS_BLOCK = "'<option>papaya</option><option>apple</option>'";
private static final String DROPDOWN_CSS_SELECTOR = "#dropdown";
private static final String CALLBACK = "function(){console.log('clicked')}";
@BeforeClass
public static void setup() {
instantiateDriver();
driver.get(Constants.DROPDOWN_PAGE_URL);
}
@Test
public static void dropDownTest() {
JavaScriptHelper javaScriptHelper = new JavaScriptHelper(driver);
//pauses execution up to 2 minutes.
javaScriptHelper.pauseTheDOMForAGivenDuration(5000);
//attaches a valid and well-formed HTML block as a child of a given element.
javaScriptHelper.appendHTMLBlockAsAChild(OPTIONS_BLOCK,DROPDOWN_CSS_SELECTOR);
//attaches a callback function to a given event in the DOM.
javaScriptHelper.attachASnippetAsAEventCallBack(DROPDOWN_CSS_SELECTOR, EventListener.CLICK,CALLBACK);
}
@AfterClass
public static void cleanUp() {
driver.quit();
}
}









No comments:

Post a Comment

What's in my Bag? EDC of a Tester