Testing SharePoint. Selenium VS SharePoint Menus


If you’ve tried to create automated Selenium tests for testing SharePoint, you probably know that to many of the UI elements of SharePoint is not easy to reach. The idea of creating such tests are not indifferent to me. Of course, I was plagued with problems. Indeed, the abundance of JavaScript in the controls does, at first glance, automation with Selenium impossible. In fact, it is not. Today I will tell you about one of the ways of working with various menus SharePoint (such as the Site Actions or Page Editor Toolbar). The way in which I’ll not ideal, because it is tied to the design, but unfortunately at the moment I find another method failed.

Likely to create tests, many of you use Selenium IDE to write it. If you tried to write Selenium tests for SharePoint, which is necessary to apply to any menu items or SharePoint, then, surely, faced with the fact that a recorded tests in the end may not be reproduced. For example, if you’re using Site Actions, then these tests fall immediately after the opening menu. The thing is that before using the menu items, it is necessary to translate the focus, ie make it active. This method will help you mouseOver (). So, in order to take advantage of any element, you need to make the following sequence:

  • click(element id)
  • mouseOver(element id)
  • clickAndWait(element id)

For example in order to go to the All Site Content must do the following (for example, a fragment of HTML script):

<tr>
<td>click</td>
<td>link=Site Actions</td>
<td></td>
</tr>
<tr>
<td>mouseOver</td>
<td>//td[@id='ctl00_PlaceHolderTopNavBar_SiteActionsMenuMain_ctl00_wsaViewAllContent']</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>//td[@id='ctl00_PlaceHolderTopNavBar_SiteActionsMenuMain_ctl00_wsaViewAllContent']</td>
<td></td>
</tr>

It is worth a little closer look at, where are ID elements. Part SiteActionsMenuMain_ctl00_wsaViewAllContent will always remain constant, but that’s all before it, will depend on the design of your application. The example shows a fragment of a script that will work on sites for which the location of the Site Actions not changed relative to the standard design. Note that for system pages, this ID will be different, narimer, the same item View All Site Content will have the following ID (given ID as valid only for the reference design of SharePoint):

<tr>
<td>click</td>
<td>link=Site Actions</td>
<td></td>
</tr>
<tr>
<td>mouseOver</td>
<td>//td[@id='ctl00_PlaceHolderTopNavBar_SiteActionsMenuMain_ctl00_SiteSettingsOptions']</td>
<td></td>
</tr>
<tr>
<td>mouseOver</td>
<td>//td[@id='ctl00_PlaceHolderTopNavBar_SiteActionsMenuMain_ctl00_AllSiteSettings']</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>//td[@id='ctl00_PlaceHolderTopNavBar_SiteActionsMenuMain_ctl00_AllSiteSettings']</td>
<td></td>
</tr>

In order to get to a point located on the second level menu (for example, Modify All Site Settings), do the following (for example, a fragment of HTML script):

That is, as is the case with elements of the first level is necessary to go to an item and then click on it.

See Also

    Advertising

    Archives