Project Description
This project offers a small, lightweight framework (and also guidance) on how it's possible to test SharePoint using selenium in a reusable and clean way. The project follows the "Page Object" design pattern, so that instead of having to parse css, ids, xpath etc, directly in your test cases, you can now deal with c# page objects to make testing more readable and reusable.

This project is still in its early stages and I am actively using it to test DocRead, so I will refine and improve as time permits. The test site for DocRead is also hosted in the cloud and I invariably do snapshot reverts, so please don't rely on it as a basis for your development and testing.

Want to know about DocRead?
If you are interested in discovering how to distribute and track policies and procedures in SharePoint - why not check out our policy management software called DocRead

To read more about this project please read this : blog post

The code snippet below is an example of how it's possible to get a collection of strongly typed objects back representing the documents presented on a standard documents library page.

[Test(Description = "Tests for a blank DocRead DB Name.")]
[Category("Central Admin")]
public void Cant_Save_Blank_DocRead_DB_Name()
{
    this.page.RefreshPage();

    this.page.Form.DatabaseServer = Ctrls.Default.FrmDbSqlServer;
    this.page.Form.DocReadDatabaseName = "";
    this.page.Form.SchedulerDatabaseName = Ctrls.Default.FrmDbSchedDatabaseName;
    this.page.Form.SchedulerServicesAccount = Ctrls.Default.FrmDbSchedulerSvcAccount;

    this.page.Save();

    Assert.That
        (this.page.Form.DocReadDatabaseNameErrorMessage == Ctrls.Default.ErrFieldCannotBeBlank);
}

[Test]
public void Test_Documents_Are_Displayed()
{
    // load and configure a new browser 
    this.Driver = this.StartAndConfigBrower();

    // logon with user (using AutoIt)
    this.Driver.LogonAsUser(TypeOfUser.DocReadAdmin);

    // Get all the documents from the library on first page
    SPTDocumentLibraryPage<DocReadDocItem> documentLibraryPage = 
        new SPTDocumentLibraryPage<DocReadDocItem>(
            this.Driver, TestSettings.DocReadDocumentsPage.Url);

    // Returns a list of documents (you can also supply your own entity).
    List<DocReadDocItem> documents = documentLibraryPage.GetDocuments();

    // Normal NUnit test assertions - but now we are testing strongly typed objects
    Assert.That(documents[0].Title == "Alcohol and drug abuse policy");
    Assert.That(documents[2].Editor  == @"AD2008R2\administrator");
    Assert.That(documents.Count == 10);


[Test]
public void Test_Feature_Management()
{
        // load and configure a new browser 
    this.Driver = this.StartAndConfigBrower();

    // logon with user (using AutoIt)
    this.Driver.LogonAsUser(TypeOfUser.DocReadAdmin);

    SPTFeaturePage featurePage = new SPTFeaturePage(
                                        this.Driver, 
                                        TestSettings.HealthCareWebFeaturesPage.Url);

    // Deactivate / Activate the Publishing Features Button.
    featurePage.ToggleFeatureState(
        Common.Map.Features.SharePointServerPublishingFeatureId);
}

To get started with ShareTest, do this :
  • Download the code from here
  • Add in your own testing CS proj
  • Add a reference to the Collaboris.ShareTest project
  • Start testing your SharePoint project.

We need help. To get decent coverage in SharePoint is going to require that "Page Objects" get created for all of the standard SharePoint pages. If you would like to help, get in touch!

More on DocRead

DocRead - used as an example in these tests - is a commercially available application that allows you to distribute important documents (such as policies) to groups of users, all from SharePoint. Each user is required to 'confirm' by accepting a policy statement, by a given deadline.

To use this SharePoint testing library in your own project, you simply need to download the code and use the DocRead test project as guidance. Once you are happy with how to use it - feel free to remove the DocRead test project..

Last edited Jan 6, 2013 at 5:39 PM by mark_q_jones, version 10