Powered By Blogger

Search Here!

Sunday, June 16, 2013

Create Logging In Webdriver !

private static IWebDriver IEWebDriver()
        {
            //Get The Machine Processor Architecture
            String getProcessorArchitecture = Microsoft.Win32.Registry.GetValue(
                "HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Control\\Session Manager\\Environment"
                , "PROCESSOR_ARCHITECTURE", null).ToString();
            //Get IE Driver Path
            String getIeDriverPath =
                (Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase)
                + "\\..\\..\\..\\..\\ExternalAssemblies\\" + ((getProcessorArchitecture == "x86") ? "x86" : "x64")).Replace("file:\\", "");
            //Start Internet Explorer Driver Service
            InternetExplorerDriverService ieservice = InternetExplorerDriverService.CreateDefaultService(getIeDriverPath);
            ieservice.LoggingLevel = InternetExplorerDriverLogLevel.Trace;
            //Get Log Execution Path
            String getExecutingPath = new FileInfo(Assembly.GetExecutingAssembly().Location).DirectoryName;
            ieservice.LogFile = Path.Combine(getExecutingPath, "Log", "IEDriver" + DateTime.Now.Ticks + ".log");
            //Set Internet Explorer Options
            InternetExplorerOptions options = new InternetExplorerOptions
                                                  {
                                                      IntroduceInstabilityByIgnoringProtectedModeSettings = true,
                                                      UnexpectedAlertBehavior = InternetExplorerUnexpectedAlertBehavior.Ignore,
                                                      IgnoreZoomLevel = true,
                                                      EnableNativeEvents = true,
                                                      RequireWindowFocus = true,
                                                  };
            //Create Internet Explorer Driver Object
            IWebDriver webDriver = new InternetExplorerDriver(ieservice, options, TimeSpan.FromMinutes(20));
            //Set WebDriver Page Load Time
            webDriver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(timeOut));
            //Set The Cursor Position Center of the Screen
            Cursor.Position = new Point(Screen.PrimaryScreen.Bounds.Width / 2, Screen.PrimaryScreen.Bounds.Height / 2);
            return webDriver;
        }

Saturday, June 8, 2013

Internet Explorer Options : Selenium !

org.openqa.selenium.ie.InternetExplorerDriver

Capabilities [{platform=WINDOWS, elementScrollBehavior=0, javascriptEnabled=true, enablePersistentHover=true, ignoreZoomSetting=false, browserName=internet explorer, enableElementCacheCleanup=true, unexpectedAlertBehaviour=dismiss, version=9, cssSelectorsEnabled=true, ignoreProtectedModeSettings=false, allowAsynchronousJavaScript=true, requireWindowFocus=false, handlesAlerts=true, initialBrowserUrl=, nativeEvents=true, takesScreenshot=true}]

InternetExplorerOptions options = new InternetExplorerOptions
                                                  {
                                                      IntroduceInstabilityByIgnoringProtectedModeSettings = true,
                                                      UnexpectedAlertBehavior = InternetExplorerUnexpectedAlertBehavior.Ignore,
                                                      IgnoreZoomLevel = true,
                                                      EnableNativeEvents = true,
                                                      RequireWindowFocus = true,
                                                      EnablePersistentHover = true,
                                                      ElementScrollBehavior = InternetExplorerElementScrollBehavior.Top,
                                                      BrowserAttachTimeout = TimeSpan.FromSeconds(timeOut),
                                                  };
 IWebDriver webDriver = new InternetExplorerDriver(ieDriverPath, options, TimeSpan.FromMinutes(20));

Properties Description

Name
Description
ElementScrollBehavior
Gets or sets the value for describing how elements are scrolled into view in the IE driver. Defaults to scrolling the element to the top of the viewport.
EnableNativeEvents
Gets or sets a value indicating whether to use native events in interacting with elements.
EnablePersistentHover
Gets or sets a value indicating whether to enable persistently sending WM_MOUSEMOVE messages to the IE window during a mouse hover.
IgnoreZoomLevel
Gets or sets a value indicating whether to ignore the zoom level of Internet Explorer .
InitialBrowserUrl
Gets or sets the initial URL displayed when IE is launched. If not set, the browser launches with the internal startup page for the WebDriver server.
IntroduceInstabilityByIgnoringProtectedModeSettings
Gets or sets a value indicating whether to ignore the settings of the Internet Explorer Protected Mode.
RequireWindowFocus
Gets or sets a value indicating whether to require the browser window to have focus before interacting with elements.
UnexpectedAlertBehavior
Gets or sets the value for describing how unexpected alerts are to be handled in the IE driver. Defaults to Default.

Importance of DSL in Automated Functional Testing

DSL is a specification language that is dedicated to a particular problem domain, a particular problem representation technique, and/or a particular solution technique. The DSL is a software solution that focuses the domain experts to spend their time more effectively describing or solving a problem as opposed to battling with a programming language. Even though this concept has been around for several years, but its implementation in the test automation space, in my opinion, is still in its early stages.
Imagine documenting your test case steps (Specifications) pretty much as you would do in your test case management system but being able to “run” these tests in an automation fashion without any coding! This is the promise that this solution can provide.
There are some tools that allows creating tests as Specifications. FitNesse and Cucumber are two such examples.
The best way to achieve good quality re-useable and robust code base is to create a Domain Specific Language for your test framework. What does it mean in simple words? Let me explain that on an example.
To run a search in your web-based application to check if the expected amount of links is returned, you need to write quite a few lines of code. Most probably you have quite a few similar Test Cases in this area. So the best thing to do is to extract all the global initiatlization functions and common actions to one object called myApplication (you name it) and methods like myApplication. runSearch (searchString, expectedNumeberOfResults, firstLinkOntheList).
When you read that code and write new Test Cases in your IDE, you will learn the structure of the framework and use it naturally. And imagine that some screen or flow changes. If you have lots of independent procedures, you have a maintenance nightmare. With use of DSL, you have to change the code in one spot only and the Test Cases will pass again. You can even leave creating the library to experienced developers and have less technical people to write agile Test Procedures. This way the test automation will be fun and rewarding.