Friday, 16 September 2016

How To Allow Jenkins To Publish ExtentReport Or Any Html Based Report Compromising Security

By default, Jenkins latest version displays Extent Report in normal text, as Extent Report contains scripts which pose threat to web security.

To overcome the problem, we have to override property - hudson.model.DirectoryBrowserSupport.CSP

Following way of overriding solves the problem-
java -Dhudson.model.DirectoryBrowserSupport.CSP="" -jar jenkins.war

MSTest Attributes Comparison With TestNG Test Attributes

using Microsoft.VisualStudio.TestTools.UnitTesting;
using SampleClassLib;
using System;
using System.Windows.Forms;

namespace TestNamespace
{
    [TestClass()]
    public sealed class DivideClassTest
    {
        [AssemblyInitialize()] //Before All Tests Across All Test Classes are run, mimics BeforeSuite in TestNG
        public static void AssemblyInit(TestContext context)
        {
            MessageBox.Show("AssemblyInit " + context.TestName);
        }

        [ClassInitialize()]//Before All Tests in Test Class is run, mimics BeforeClass in TestNG
        public static void ClassInit(TestContext context)
        {
            MessageBox.Show("ClassInit " + context.TestName);
        }

        [TestInitialize()] //Before Each Test Is Run, mimics BeforeTest in TestNG
        public void Initialize()
        {
            MessageBox.Show("TestMethodInit");
        }

        [TestCleanup()] //After Each Test Is Run, mimics AfterTest in TestNG
        public void Cleanup()
        {
            MessageBox.Show("TestMethodCleanup");
        }

        [ClassCleanup()] //After All Tests In Test Class are executed, mimics AfterClass in TestNG
        public static void ClassCleanup()
        {
            MessageBox.Show("ClassCleanup");
        }

        [AssemblyCleanup()] //After All Tests Across All Test Classes are executed, mimics AterSuite in TestNG
        public static void AssemblyCleanup()
        {
            MessageBox.Show("AssemblyCleanup");
        }

        [TestMethod()] //Test Method To Be Executed, mimics Test in TestNG
        [ExpectedException(typeof(System.DivideByZeroException))]
        public void DivideMethodTest()
        {
            DivideClass.DivideMethod(0);
        }
    }
}

Thursday, 15 September 2016

MSTest Options

running MSTest from commandline:
https://msdn.microsoft.com/en-us/library/ms182486.aspx

General Command Line Options
/testcontainer:[file name]
Load a file that contains tests.
Example: /testcontainer:tests.dll 
For more information, see /testcontainer.
/testmetadata:[file name]
Load a file that contains test metadata. For more information, see /testmetadata.
/testlist:[test list path]
Specify the test list, as specified in the metadata file, to be run. For more information, see /testlist.
/category:[test category filter]
Specify and filter which test categories to run. For more information, see /category.
/test:[test name]
Specify the name of a test to be run. For more information, see /test.
/noisolation
Run tests within the MSTest.exe process. This choice improves test run speed but increases risk to the MSTest.exe process.
/testsettings: [file name]
Use the specified test settings file.
Example: /testsettings:Local.Testsettings
For more information, see /testsettings.
/runconfig:[file name]
Use the specified run configuration file.
Example: /runconfig:localtestrun.Testrunconfig
For more information, see /runconfig.
System_CAPS_noteNote
This command-line option is maintained for compatibility with previous versions of Visual Studio. Test run configurations have been replaced by test settings in Visual Studio Enterprise.
/resultsfile:[file name]
Save the test run results to the specified file.
Example: /resultsfile:testResults.trx
For more information, see /resultsfile.
/detail:[property id]
Specify the name of a property that you want to show values for, if any, in addition to the test outcome. For more information, see /detail.
/help
Display the MSTest.exe usage message (short form: /? or /h).
/nologo
Display no startup banner and copyright message.
/usestderr
Use standard error to output error information.

Automating dropdowns/lists

Selecting Item/Items in ListBox:
3 Possbile Methods exposed by Select Class:
1. SelectByText
2.SelectByValue
3.SelectByIndex

Friday, 23 October 2015

WebServer Vs Application Server

1. Application Server supports distributed transaction and EJB. While Web Server only supports Servlets and JSP.
2. Application Server can contain web server in them. most of App server e.g. JBoss or WAS has Servlet and JSP container.
3. Though its not limited to Application Server but they used to provide services like Connection pooling, Transaction management, messaging, clustering, load balancing and persistence. Now Apache tomcat also provides connection pooling.
4. In terms of logical difference between web server and application server. web server is supposed to provide http protocol level service while application server provides support to web service and expose business level service e.g. EJB.
5. Application server are more heavy than web server in terms of resource utilization.

Read more: http://javarevisited.blogspot.com/2012/05/5-difference-between-application-server.html#ixzz3pSqJsgKx

Sunday, 30 August 2015

DesiredCapability For Cloud Environment SauceLabs Vs BrowserStack

Additional Keys Are Supported For Setting Desired Capabilities W.R.T execution on cloud environment:

1. Account Name: username=<AccountName>
2. AccessKey : accessKey=<AccessKey>

Example:
/*Below snippet does belong to C# conventions*/
private void setRemoteWebDriverForCloudSauceLabs()
        {
            DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
            desiredCapabilities.SetCapability(CapabilityType.BrowserName, this.browser);
            desiredCapabilities.SetCapability(CapabilityType.Version, this.version);
            desiredCapabilities.SetCapability(CapabilityType.Platform, this.platform);
            desiredCapabilities.SetCapability("username", this.userName);
            desiredCapabilities.SetCapability("accessKey", this.accessKey);
            desiredCapabilities.SetCapability("name", this.executedFrom + " - " + this.jobName + " - " + this.buildNumber + " - " + TestContext.CurrentContext.Test.Name);
            Uri commandExecutorUri = new Uri("http://ondemand.saucelabs.com/wd/hub");
            this.driver = new RemoteWebDriver(commandExecutorUri, desiredCapabilities);
        }

The same url for saucelabs connection can also contain username and accesskey. For example:
Uri commandExecutorUri = new Uri("http://<username>:<accessKey>@ondemand.saucelabs.com:80/wd/hub");

/*For BrowserStack*/

private void setRemoteWebDriverForCloudBrowserstack()
        {
            DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
            desiredCapabilities.SetCapability("browser", this.browser);
            desiredCapabilities.SetCapability("browser_version", this.browser_version);
            desiredCapabilities.SetCapability("os", this.os);
            desiredCapabilities.SetCapability("os_version", this.os_version);
            desiredCapabilities.SetCapability("browserstack.user", this.browserstack_user);
            desiredCapabilities.SetCapability("browserstack.key", this.browserstack_key);
            Uri commandExecutorUri = new Uri("http://hub.browserstack.com/wd/hub/");
            this.driver = new RemoteWebDriver(commandExecutorUri, desiredCapabilities);
        }

How to get list of desiredcapabilities:
SauceLabs: Set Environment Using Utility Given At PlatformConfigurator
1. PlatformConfigurator: https://docs.saucelabs.com/reference/platforms-configurator

 

Thursday, 23 April 2015

Unit testing best practices

Unit testing is not about finding bugs
Tips for writing great unit tests
Test only one code unit at a time
Don’t make unnecessary assertions
Make each test independent to all the others
Mock out all external services and state
Don’t unit-test configuration settings
Name your unit tests clearly and consistently
Write tests for methods that have the fewest dependencies first, and work your way up
All methods, regardless of visibility, should have appropriate unit tests
Aim for each unit test method to perform exactly one assertion
Create unit tests that target exceptions
Use the most appropriate assertion methods.
Put assertion parameters in the proper order
Ensure that test code is separated from production code
Do not print anything out in unit tests
Do not use static members in a test class
Do not write your own catch blocks that exist only to fail a test
Do not rely on indirect testing
Integrate Testcases with build script
Do not skip unit tests
Capture results using the XML formatter
Details: http://howtodoinjava.com/2012/11/05/unit-testing-best-practices-junit-reference-guide/