C#: Selenium Framework: 1 - Main

Components & Tools

Tools

Description

FireFox

For Development

SeleniumIDE

FireFox Plugin for Rudimentary Capture/Playback, exposes the WebDriver calls for each action, and stores test suites for recorded tests.

Firebug

FireFox Plugin for exposing web page controls, code and content

VisualStudio2012

Resharper plugin

XMLSpy

XML, XSD editing

BeyondCompare

Comparing file results

Internet Explorer

Target Browser for UAT testing

Current Framework Facets

File

Description

UnitTest

Drives the basic unit of action and serves as a place to initialize test dependencies

FormData.xml

Models WebBrowswer by enumerating each page and giving each control an id, ControlType, and Option value.

JobData.xml

Models each type of PET image job for data driven tests. This will allow for the same framework to perform a wide variety of operations by modifying the XML input file

ImageData.xml

Models each type of PET Operating System Image to allow for automatic detection of default values required for successful submissions through the PET product.

 

 

DataPageSubmit

Reads the XML files and pipes data to persistent objects much like a database

Controls

Enumerates the various types of controls employed in the PET interfaces

 QwPageSubmit

For each page in Quick Web, an associated page class is used to drive all actions performed on the page. This class will look to its corresponding ‘Data Object’ for what values to enter.

Pages

Conjures the various PET web pages and serves as a layer of abstraction so Unit Tests are simple to create, maintain, and read.

Browser

Interface to the Selenium WebDriver and allows changes to the browser interface without requiring widespread changes to the entire framework

WebDriver

 Driver that communicates with Internet Explorer, FireFox, and Chrome and provides the C# libraries to drive the component

Code Metrics

Item

Description

Project

“TestFramework”

Configuration

 

Maintainability Index

75

Cyclomatic Complexity

86

Depth of Inheritance

1

Class Coupling

48

Lines of Code

516

 

Re-Sharper Unit Test Details

DGML Class Diagrams

VS2012 Solution Explorer and Class View

Unit Test Example

 

    [TestClass]

    public class UnitTest3

    {

        private JobsQw Jobs = new JobsQw(); //Class for grouping Tables of Options with Values

 

        [TestMethod]

        public void SubmitQwJob()

        {

            DataPageSubmit.XmlFormDataInit();

            DataPageSubmit.XmlJobDataInit();

            Jobs.SelectJobType(); // Select Project SI and Service Type

            Jobs.ImageValidation(); // Image validation job...

 

            Browser.Quit(); // Quit the Browser and Page Server

        }

    }

 

Job Batching Interface

    public class JobsQw

    {

        public void SelectJobType()

        {

            Pages.QwSubmitPage.Goto();

            Pages.QwSubmitPage.IsAt();

            Pages.QwSubmitPage.EnterSiNumber();

            Pages.QwSubmitPage.SelectQwJob();

            Pages.QwSubmitPage.ClickSiButton();

        }

 

        public void ImageValidation()

        {

            Pages.QwSubmitPage.DownloadLocation();

            Pages.QwSubmitPage.ImageOperatingSystem();

            Pages.QwSubmitPage.SelectSubfolder();

            Pages.QwSubmitPage.SelectImage();

            Pages.QwSubmitPage.OutputImageType();

            Pages.QwSubmitPage.MultipleCustPartition();

            Pages.QwSubmitPage.MiscFactoryPatch();

            Pages.QwSubmitPage.MiscInstallDrivers();

        }

    }

 

Browser Interactions

        public void MultipleCustPartition()

        {

            /*  Util?Y/N              LeaveUnallocated?Y/N

             *  UnitType?%/G/M        Total

             *  1:    Size    FileSys     New?

             *  2-7:  Size    FileSys     New?

             */

            // Util: Sel: Y,N

            var selUtil = Browser.Driver.FindElement(By.Id(DataPageSubmit.CustomPart.UtilPartition.id));

            var selElemUtil = new SelectElement(selUtil);

            selElemUtil.SelectByValue(DataPageSubmit.CustomPart.UtilPartition.Option);

 

            //LeaveUnallocated: Sel :Y,N

            var selLeave = Browser.Driver.FindElement(By.Id(DataPageSubmit.CustomPart.LeaveUnallocated.id));

            var selElemLeave = new SelectElement(selLeave);

            selElemLeave.SelectByValue(DataPageSubmit.CustomPart.LeaveUnallocated.Option);

 

            //Unit Type: Sel: Blank,%,M,G

            var selUnit = Browser.Driver.FindElement(By.Id(DataPageSubmit.CustomPart.UnitType.id));

            var selElemUnit = new SelectElement(selUnit);

            selElemUnit.SelectByValue(DataPageSubmit.CustomPart.UnitType.Option);

 

            //Part1 Size: Text

            var txtElemP1Size = Browser.Driver.FindElement(By.Id(DataPageSubmit.CustomPart.CustPart1Size.id));

            txtElemP1Size.SendKeys(DataPageSubmit.CustomPart.CustPart1Size.Option);

 

            //Part1 FileSys: Sel: Blank, FAT16, FAT32, NTFS

            var selFileSys = Browser.Driver.FindElement(By.Id(DataPageSubmit.CustomPart.CustPart1FileSystem.id));

            var selElemFileSys = new SelectElement(selFileSys);

            selElemFileSys.SelectByValue(DataPageSubmit.CustomPart.CustPart1FileSystem.Option);

 

            //Part1 New? Checkbox: Y,N

            var checkNew = Browser.Driver.FindElement(By.Id(DataPageSubmit.CustomPart.CustPart1New.id));

            if ((!checkNew.Selected) && (Convert.ToBoolean(DataPageSubmit.CustomPart.CustPart1New.Option)))

            {

                checkNew.Click();

            }

        }

XML model of PET QuickWeb Submit Page

Tags