In Java, starting a test in selenium with a DefaultSelenium object, how can I find in which browser the test works?

Consider a simple DefaultSelenium object

DefaultSelenium sel = new 
      DefaultSelenium("http://localhost:8080/myapp",4444,"*iexplore","/myAppLevel1");

Now my server is configured with the -forcedBrowserMode "* firefox" option on the command line when I start it. However, I have two different batch files to start the server, one of which is forcibly used in firefox, one of which is forcibly connected to IE. FYI, -forcedBrowserMode overrides the settings inside the Java object instance.

The problem is in java, I cannot find a way to determine in which browser my DefaultSelenium object works ... I thought something like:

sel.getBrowserName();

But nothing of the kind exists. Are there any other creative ways to do this?

I need to know, because using the GWT web application to click on a button, you need to do it differently based on the browser. Alternatively, you may wonder why I even use -forcedBrowserMode, because then I can use the custom firefox / ie settings to test.

Thanks in advance for your help!

+3
source share
1 answer

I think that you can get the browser by running some JavaScript, for example, check navigator.userAgentor some specific object, for example, document.defaultViewwill be null in IE and not null in FF, something like this:

DefaultSelenium sel = ...
String res = sel.getEval("document.defaultView ? false : true");
boolean isIE = "true".equals(res);
+1
source

Source: https://habr.com/ru/post/1755867/


All Articles