In Java, starting a test in selenium with the DefaultSelenium object how do I find which browser the test is running on?
Consider a simple DefaultSelenium object
DefaultSelenium sel = new
DefaultSelenium("http://localhost:8080/myapp",4444,"*iexplore","/myAppLevel1");
Now my server is set with the option of -forcedBrowserMode "*firefox" in the command line when I start it up. However, I have 2 different batch files to start the Server, one forced in firefox, one forced to IE. FYI, the -forcedBrowserMode overrides the settings within of the instantiated java object.
The problem is from java, I can't seem to find a way to determine which browser my DefaultSelenium object is running on... I was thinking something like:
sel.getBrowserName();
But nothing like that exists. Are there any other creative ways of doing this?
I need to know because w开发者_如何学Goith a GWT web application, to click on a button you need to do it differently based on the browser. As well, you may wonder why I even use the -forcedBrowserMode, because then I can use custom setup firefox/ie installs to test on.
Thanks in advance for help!
I think that you can get the browser by executing some JavaScript, for example verify navigator.userAgent
or any browser specific object, for example document.defaultView
will 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);
精彩评论