Only trigger a release when the build changed

Back in the early days, when we used XAML builds in TFS (wow that seems like ages ago!), we had the possibility to NOT execute a build when nothing changed in the source code repository. This checkbox “Build even if nothing has changed” does not exist anymore in VSTS.

For me this is not a real problem, when you build your source code, it is also a validation if your underlying system is OK. It is more a problem when you automatically trigger a release pipeline after a nightly build. Why should you release a new version of your application, when it is not a new version but exactly the same version. Of course, we can discuss that it should not be a problem, that you should always be able to release, but still. It is unneccessary and sometimes even not wanted.
Read more →

Testing web apps on Edge using CodedUI

Recently Microsoft added the capability to CodedUI to test on the Edge browser. For this they extended the cross browser playback capability. This uses Selenium under the hood. So the steps to make this work are as follows:

 

  • Install the plugin “Selenium components for Coded UI Cross Browser Testing” from the Visual Studio Gallery (found here)
  • Download the Edge driver that matches your windows 10 version (found here)
  • Install the driver to the following location : %ProgramFiles(x86)%Microsoft Web Driver

And finally in the code you need to switch the browser you want to launch. You need to provide the following name to start edge:”MicrosoftEdge”

BrowserWindow.CurrentBrowser = “MicrosoftEdge”; 

var browserWindow = 
    BrowserWindow.Launch(new Uri("<your URl here>"));

And that is it!

Happy testing on Edge Smile

My VSLive Sessions

If you attended one of my sessions, I hope you enjoyed them. I had a great time.

czkn1fvw8aey3mm

For your reference you can find the PDF’s here and the accompanying demo code.

Continuous delivery on azure: A/B testing, Canary releasing and Dark launching

If you are more interested in Continuous delivery, you also might like my just published course at Pluralsight called “Building a Continuous Delivery Pipeline with TFS and Visual Studio 2015” which you can find here: https://www.pluralsight.com/courses/tfs-visual-studio-2015-implementing-continuous-delivery

My second session was on Micro Services and you can find the PDF here:

VSH11 Exploring Microservices in a Microsoft Landscape

And the final session was on building maintainable cross browser UI tests with either selenium or codedUI. The PDF can be found here:

VSH16 Writing Maintainable X-Browser Automated Tests

and you can find the demo’s here: Search google

Also if you want to learn more about CodedUI, you can also watch one of my two courses I build for Pluralsight here:Test Automation with CodedUI Pluralsight which explains in detail all that can be done with CodedUI and Testing Web Applications with CodedUI Pluralsight which is focused on testing web applications.

if you don’t have a subscription yet, you can watch it for free with the free trial

Hope you enjoyed it, if you have comments or feedback let me know!

Cheers,

Marcel

How to fix “Error: This access control list is not in canonical form and therefore cannot be modified. Error count: 1”

In my previous post about Deploying ASP.NET 4.5 to Docker on Windows I forgot to mention that you might run into an issue when running webdeploy.

Julian Perrott, commented on my post and asked if this is an issue. I think it is an issue and that the install does not complete correctly. But there is an easy fix for this as well. What you can do is add a small PowerShell script to your Docker image and run that after the first attempt to deploy the website. Then the next step is to run the script to fix the ACL’s and then again run web deploy. I have not yet tried this on the latest Windows server 2016 bits, but on the Technical preview 5 this worked like a charm.

You need the following script to fix the ACL’s:

$path = "C:inetpubwwwrootMvcMusicStore_deploy"
$acl = Get-Acl $path
Set-Acl $path $acl

This script doe nothing more then getting the ACL on the path and then re-apply it. this will make windows fix the ACL and make them in canonical form again.

You can add this to your dockerfile and make it part of your standard install of a website in your release pipeline.

FROM windowsserveriisaspnetwebdeploy 
RUN mkdir c:webapplication
WORKDIR /webapplication
ADD fixAcls.ps1 /MvcMusicStore/fixAcls.ps1
ADD dockerdeploydemo.zip  /webapplication/dockerdeploydemo.zip
ADD dockerdeploydemo.deploy.cmd /webapplication/dockerdeploydemo.deploy.cmd
ADD dockerdeploydemo.SetParameters.xml /webapplication/dockerdeploydemo.SetParameters.xml
RUN dockerdeploydemo.deploy.cmd, /Y
RUN powershell.exe -executionpolicy bypass .fixAcls.ps1
RUN dockerdeploydemo.deploy.cmd, /Y

So this does nothing more then adding the little PowerShell script to the container and then using that in the step after deploying your website

Hope this helps!

How to Fix Application insights Live Metrics stream on Azure Mobile Apps

In preparation for Tech Days 2016, I was working with my colleagues on the Techdays app and for this we also have a backend system. This system is running for some time now and we want to have better insights into the usage of the website and the mobile app.

One of the latest additions to application insights is the capability of Live Metrics, where you can see the current traffic coming into your website or API.

For this you can simply add a NuGet package, which is currently in pre-release, but works great.

Once you install the package and run the website, you will see the Live Stream tile light up in the Azure portal and when you click it you will see a couple of live graphs showing actual traffic on the site or API

Of course we wanted to host our backend very simply on Azure Web apps and for this specific purpose on Azure Mobile Services, Since that is what we use as the mobile backend of the application. But apparently there are some subtle differences that prevent AppInsights to work properly if it comes to Live Metrics.

When running the web API on a local machine with app insights enabled, we could see a nice set of graphs as shown here below:

clip_image002

But when I deploy this to the Azure Mobile services, this results in a page that only shows the dependency calls, bet never any incoming requests and also no request duration. You only see a first request and after this the incoming requests are a flat liner.

clip_image001

After some inquiries at the app insights team, I got the information that since Azure Mobile Services is using OWIN, because the app insights HTTP modules are not loaded since that is not allowed and finally because performance counters are not exposed to the web application, these metrics will not show. After going back and forth on this, I got information that it would be possible to at least get the info for the requests on the screen, by adding a small piece of middleware, that can track the request instead of the standard HttpModule that is normally instantiated, but not allowed in a Mobile app.

So the only thing I needed to do is create a middleware component like the following:

public class ApplicationInsightsMobileAppRequestHandler : OwinMiddleware
{
   private readonly TelemetryClient telemetryClient;
   public ApplicationInsightsMobileAppRequestHandler(OwinMiddleware next) : base(next)
   {
    try
    {
      // The call initializes TelemetryConfiguration that will create and Intialize modules
      TelemetryConfiguration configuration = TelemetryConfiguration.Active;
      telemetryClient = new TelemetryClient(configuration);
    }
    catch (Exception exc)
    {
      Trace.WriteLine("Error initializing Handler");
      Trace.WriteLine(exc.Message);
    }
}

public override async Task Invoke(IOwinContext context)
{
  var operation = telemetryClient.StartOperation&lt;RequestTelemetry&gt;(context.Request.Path.Value);
  try
  {
    var requestTelemetry = operation.Telemetry;
    await this.Next.Invoke(context);
    requestTelemetry.HttpMethod = context.Request.Method;
    requestTelemetry.Url = context.Request.Uri;
    requestTelemetry.ResponseCode = context.Response.StatusCode.ToString();
    requestTelemetry.Success = context.Response.StatusCode >= 200 && context.Response.StatusCode < 300; 
  }
  catch (Exception exc)
  {
    var telemetry = new ExceptionTelemetry(exc);
    telemetry.HandledAt = ExceptionHandledAt.Unhandled;
    telemetryClient.TrackException(telemetry);
  }
  finally
  {
    telemetryClient.StopOperation(operation);
  }
 }
}

And an extension method to register the middleware in the request pipeline at startup in the Startup class:

public static class AppBuilderExtensions
{
  public static IAppBuilder UseMobileAppRequestHandler(this IAppBuilder app)
  {
     return app.Use<ApplicationInsightsMobileAppRequestHandler>();
  }
}

In the application startup class, ensure that you register this handler as the first as follows:

public static void ConfigureMobileApp(IAppBuilder app)
{
  HttpConfiguration config = new HttpConfiguration();
  app.UseMobileAppRequestHandler();
  app.UseWebApi(config);
  ConfigureSwagger(config);
}

And that is it!

When you now deploy tot the azure mobile app, you will see the live metrics as we expect. We still don’t have the memory consumption and CPU usage stats, but this now at least shows all incoming requests in real time

Hope this helps!

Marcel

Upgraded my blog to Project Nami on Azure

My blog has been running on WordPress in combination with Microsoft Azure since the start. I always disliked the fact that i had to get a MySQL database using ClearDB to host it but it seemed the only way. A few days ago i made some mistakes and kinda broke my current blog (i won’t bother you with the details 😉 ) and had to do some reinstalls. Since quite some time passed i thought it might be good to do some research in the current possibilities of using native azure components for my datastorage.

the first thing i found was using MySQL in app with your Azure web app. This removes the dependency of ClearDB but you’ll still have some limitations such as being limited to a single instance and no features for access your database remotely.

Screen Shot 2016-09-01 at 08.28.08

more info on MySQL in App preview:  https://blogs.msdn.microsoft.com/appserviceteam/2016/08/18/announcing-mysql-in-app-preview-for-web-apps/

When i looked a bit further i found another cool project called “Project Nami“. Nami stands for Not Another MySQL Install and is a fork of WordPress that changed the database layer to talk T-SQL so they could add SQL Azure as the database layer.

ProjectNamiLogo

Installing it was pretty easy. you can just get it from the Azure Marketplace when you search for “WordPress” or “project Nami” and after that it was installed in a few minutes.

Screen Shot 2016-09-01 at 08.33.16

I have to say the performance is great! the initial costs seem to be lower than they were before and my blog seems to be a lot more responsive. I really liked the upgrade to Project Nami so thought I share it with you so you might consider making the same switch if you are still running wordpress + mysql on Azure.

One downside of my screwing up my previous blog instance is that all comments are kinda lost. so thats why you might not see any comments on my older posts anymore.

Geert van der Cruijsen

 

The post Upgraded my blog to Project Nami on Azure appeared first on Mobile First Cloud First.

Fixing Windows 10 non-responsive start menu

I was just doing my work on windows 10 and for no apparent reason the windows 10 start menu would not respond anymore to either my Windows hotkey on the keyboard or by clicking on the start menu icon in the left bottom corner. This meant no response to the windows key and me typing the application I wanted to start, not being able to shut down my machine, etc. So this gave me some real headaches because the only way I could solve this is do a reset of my PC or just repaving my machine and install windows 10 again.

This has happen to me several times and most of the time after I had been doing some Mobile App development where I build mobile apps that are cross platform. Lately I had to do this for my talk at VS Live in Las Vegas and for that I had to turn on developer mode on my windows 10 machine.

Now I am not sure if his issue is caused by the mobile development I have done or if it is just my SSD drive acting up on me and corrupting certain files on my system. I do know that running the following powers shell command (started in administrator mode of course) solved the problem form me:

Get-AppXPackage -AllUsers | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)AppXManifest.xml"}

The option DisableDevelopmentMode does the following:

Registers an existing app package (.appx) installation that has been disabled, didn’t register, or has become corrupted. Use DisableDevelopmentMode to specify that the manifest is from an existing installation and not from a collection of files in development mode.

At least this was a way to solve it for me and hopefully it will work for you as well.

Selenium syntax for CodedUI

I have been playing around with this idea for quite some time and I already build this for a customer in the past, but after questions I got from people using CodedUI who tried to come up with a simplified syntax I thought it would be time to publish what I have at the moment.

If you hand code your test automation with CodedUI, then you know that searching for a control is always a couple of lines of code to set up a search. You first create an instance of the control you need, provide it the search scope in the constructor and next you need to set the search properties. Once that is done you can then use the control and the moment you use one of it’s properties it will search for your control.

With Selenium this is a bit different. You have the Driver class that provides more or less to primary methods. FindElement and FindElements and you provide it an instance of the By class that contains the search criteria.

Let me illustrate what I mean with two examples. Bot do the same. We goto the google home page and type a search query.

CodedUI:

BrowserWindow b = BrowserWindow.Launch(new Uri("http://google.com"));
HtmlEdit searchBox = new HtmlEdit(b);
searchBox.SearchProperties.Add(HtmlEdit.PropertyNames.Id, "lst-ib");
Keyboard.SendKeys(searchBox, "codedUI Course{Enter}");

Selenium:

var driver = new ChromeDriver(@"driverfolder");
driver.Navigate().GoToUrl("http://google.com");
var searchBox  = driver.FindElement(By.Id("lst-ib"));
searchBox.SendKeys("codedUI Course{Enter}");

In general I hear that people like the Selenium syntax more then the multistep aproach in codedUI. The thing I dislike is that I lose the type safety of the type of control. So the question is, would it be possible to get the same syntax for codedUI and still use codedUI and get a type safe way of interacting with the search controls?

The awnser is (of course) yes this is possible by creating a couple of extension methods and a nifty implementation of the By class.

So let me first show you how this looks when you use the extension methods I created:

CodedUI with Selenium Syntax:

BrowserWindow b = BrowserWindow.Launch(new Uri("http://google.com"));
var searchBox= b.FindElement<HtmlEdit>(By.Id("lst-ib"));
searchBox.SendKeys( "codedUI Course{Enter}");

So now I have the type safety I am used to with codedUi but I have the more terse syntaxt for finding elements of a certain type.

So how does this extension method look like?
So first I created an extension method on UITestControl that looks like follows:

public static T FindElement<T>(this UITestControl container, Func<UITestControl,HtmlControl,HtmlControl> 
 controlConstructorFunct) where T:HtmlControl , new()
{
   var control = new T {Container = container};
   controlConstructorFunct(container, control);
   return control ;
}

 

now the magic is in the fact that we pass this function a function that can initialize the control we just instantiated with the right search properties.

This is the implementation of the By class I just mentioned. It looks like follows:

public class By
{
  public static Func<UITestControl, HtmlControl,HtmlControl> Id(string id)
  { 
    return (container,control) =>
    {  
       control.SearchProperties.Add(HtmlControl.PropertyNames.Id, id);            return control;
    };
  }
}

 

Now the only thing we need to do is implement this on all the standard types of ways to find a control. So that would be by CSS class, By CSS query, By innerText, etc.

the final thing we need is an extension method on the UITestControl for handling mouse clicks and keyboard handling. those look like follows:

public static void Click(this UITestControl control)
{
  Mouse.Click(control);
}

public static void SendKeys(this UITestControl control, string text)
{
  Keyboard.SendKeys(control, text);
}

The final thing I did was also implement the way we do a search by css query a bit different. As I described in previous posts the way to find a control based on e.g. custom attributes as is the case with Angular sites, I use an implementation that calls a piece of Java script. This will then return the object and we need to ensure it is of the type we expect. Only restriction is that this is called on a UITestControl of the type BrowserWindow. Unfortunately I have not found a way to enforce this in the compiler, so I implemented that as a runtime check.

The code for this looks like follows:

public static Func<UITestControl, HtmlControl, HtmlControl> 
                                     CssSelector(string cssSelectorToFind)
{
  const string javascript = "return document.querySelector('{0}');";
  var scriptToExecute = string.Format(javascript, cssSelectorToFind);
  return (container, control) =>
  {
    var browserWindow = container as BrowserWindow;
    if(browserWindow==null)
      throw new 
              ArgumentException("You can only use the CSSSelector function on a control of type BrowserWindow");

   var searchControl = 
            browserWindow.ExecuteScript(scriptToExecute) as HtmlControl;

   var foundControltype = searchControl?.GetType();
   var returnType = control.GetType();
   if (foundControltype?.FullName == returnType.FullName)
   {
      control = searchControl;
   }
   else
   { 
      throw new InvalidCastException(
     $"Unable to assign control found to type {returnType.FullName}, control is of type {foundControltype?.FullName}");
   }
   return control;
  };
}

I put the final code here on GitHub, so you can easily download and contribute if you have additional insights.

What I shared is not complete, but I rather share it now then wait for me to find the time to finish it to support the whole Selenium set of methods.

Let me know what you think.

Hope this helps!