How to highlight an element on the webpage?

it is far from being concrete, it is jus mud.
any bling bling introduced into the testing process it is just another bias, reason for additional headache and flaky tests.
just saying…

I edited the post by Bob_H presented at How to highlight an element on the webpage? - #5 by Bob_H

  1. I encoded the code with a pair of triple backticks to present it using Code Formating
  2. I removed redundant Newline characters, to make it compact
  3. I changed the indentation of lines for better readability

The Bob_H’s code needs a slight change.

wrong:

public class HighlightElement {

    static WebDriver driver = DriverFactory.getWebDriver()

    @Keyword
    public static void run(TestObject objectto) {
        try {
            WebElement element = WebUiCommonHelper.findWebElement(objectto, 20);
            ...

right:

public class HighlightElement {

    @Keyword
    public static void run(TestObject objectto) {
        try {
            WebDriver driver = DriverFactory.getWebDriver()
            WebElement element = WebUiCommonHelper.findWebElement(objectto, 20);
            ...

My proposal

The driver variable should not be declared as a static class-scoped variable. If you use the keyword in a Test Suite, the keyword will be called multiple times by constituant Test Cases; while the driver varible is initialized only once when the first Test Case is loaded to Java VM. The second and third call to the keyword will refer the driver variable with “Session ID is null”, and will fail.

Rather, You want to use the active instance of WebDriver in each Test Cases. So you want to initialize it everytime you call the run method. Therefore the driver variable should be declared inside the run method.

@grylion54 @kazurayam @anon46315158 Im getting this error whenver I run a Test Suite. And I know that Test Suite is just a collection of Test cases. Hope you can help me with this. The Blinker Code is running If I run it in a test case, but if I Run a test suite Im having this error.

@kazurayam this actually works,.