selenium2 · springside/springside4 wiki · github

Posted by millikan at 2020-02-27

##Overviewwebdriver has changed into selenium 2.0. Compared with selenium 1.0, it directly calls the browser core API faster than JavaScript 1.0. In addition, its by locator is clearer than string 1.0, and the API of wait for an event is also improved.

But its other API is not as convenient as 1.0, but at this level, it has become the draft of W3C specification

Therefore, SpringSide provides a selenium package in the test module, which integrates the advantages of both and makes the API friendly again. When repackaging, it refers to the implementation of its backward compatible webdriverbackedselenium. Webdriverbackedselenium is implemented in JavaScript in some places, and some APIs are not implemented, so it is not used directly.

##Selenium 2. Java × 1. Setstopatshutdown() closes selenium when the JVM exits. Because every time you create a selenium entity requires considerable consumption, you want to start selenium only once throughout the test. However, JUnit does not have the concept of executing a function after all tests are completed, so it registers a JVM shutdown hook and calls selenium's quit () method when the JVM exits.

###2. The waitforpageload (timeout) function of waitforpageload() selenium 1.0 is gone, and those get (URL) and click (by) functions that promise to block until the page is fully opened have no effect in Firefox.

Fortunately, there is another solution, implicitly wait for findbyelement() to fail, and implicitly wait until the element appears. In this way, even the annoying waitforpage () of 1.0 is saved.

###3. It is a very important function to automatically snapshot senium 1.0 when there is an error. You can take a screenshot at the moment when the page is wrong. A picture is better than a thousand words. It's better to slowly look at the log and guess which step is wrong. Sometimes you can't figure it out. I also wrote a JUnit rule to automate this process, and put it in all selenium base classes.

###4. The driver.get (URL) of open (URL) 2.0 has to input the complete path, and the relative path is not allowed. I have to copy the compatibility function. If the path is relative, the baseurl will be added automatically

###5. The type of type (by, text) 2.0 does not care whether there is a value in the input box, so you have to fill in a clean () by yourself

###6. Check / uncheck / ischecked series 2.0 does not have the concept of check box, but only isselected, which helps it to be backward compatible.

###7. Select series. When processing the select box, there is an in the support package. There are a lot of functions available, such as

###8. GetValue (by) alas, in the abstract object of webelement, getValue needs to call element. Getattribute ("value") to encapsulate it.

###9. waitfor series waitfor is a very important function in Ajax testing. Another awesome object in 2 of support packages is waitForTitleIs (title), waitForTitleContains (title), waitForTextPresent (waitForTitleContains, title,), Selenium2 (waitForTitleContains, title), Selenium2 (title, Selenium2) in Selenium2.

However, there are more conditions to use in expectedconditions, such as:

###10. Other 1.0-specific functions

##Htmlunitdriver and remotedriver run on Jenkins's Linux machine, which usually does not have xwindows and cannot run a real browser. At this time, there are two options:

One is the htmlunitdriver. Instead of using a real browser, it uses htmlunit. The advantage is that it's super fast (which is very important), and it doesn't need X window. But it doesn't support JavaScript by default. It needs to be set to true in the constructor or setter function, but it can't guarantee that its behavior is the same as that of the browser, and not 100% of JavaScript supports it. Take a chance, for example, the latest jQuery 1.9.1 has reported an error again, so it decided to give up.

The other is remotedriver. Find a Windows machine to start a selenium server, download a selenium-server-standalone-2.x x.x.jar, and then run it with Java - jar You can add - dport = 3333 to reset the port. The default is 4444. Then you can refer to the method in webdriverfactory, connect to http: / / hostname: 4444 / WD / hub, and specify the desired browser to execute. creates a webdriver class based on the DriverName string, which is convenient to switch the test browser at any time in the configuration file and the - D system variable. Firefox, ie and chrome are supported as well as the definition of the removed driver.

Information on the data