Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
143 views
in Selenium by
I have a scenation where I need to print which element is being worked on on console. I am identifying element and passing it to one function where all clicking and waiting for an element happens. I am currently printing element.toString() but its giving me lots of informations. I need just By to be displayed on screen? Have anyone tried this?

1 Answer

0 like 0 dislike
by
selected by
 
Best answer
You may extend your RemoteWebDriver class as below.


import java.io.File;
import java.io.FileNotFoundException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
import java.util.Set;

import org.openqa.selenium.Capabilities;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.CommandExecutor;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.Response;

public class xRemoteWebDriver extends RemoteWebDriver {
    private boolean debug = true;

    public xRemoteWebDriver(CommandExecutor executor,
            Capabilities desiredCapabilities, Log log) {
        super(executor, desiredCapabilities);
    }

    public xRemoteWebDriver(Capabilities desiredCapabilities, Log log) {
        super(desiredCapabilities);
    }

    public xRemoteWebDriver(URL remoteAddress,
            Capabilities desiredCapabilities, Log log) {
        super(remoteAddress, desiredCapabilities);
    }

    @Override
    protected Response  execute(String driverCommand, Map<String, ?> parameters){
        printCommands(driverCommand, parameters);
        return super.execute(driverCommand, parameters);
    }
   
    private void printCommands(String driverCommand, Map<String, ?> parameters){
        System.out.print("\n");
        if(isDebug()){
            try{
                System.out.print(driverCommand);
                Set<String> keys = parameters.keySet();
                for(String key : keys)
                    System.out.print("\t"+key + "\t" +parameters.get(key));
            }catch(Exception ignore){
               
            }
        }
       
    }
   
    public boolean isDebug() {
        return debug;
    }

    public void setDebug(boolean debug) {
        this.debug = debug;
    }

}


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

1.4k questions

1.6k answers

866 comments

1.9k users

...