Azure Follow Up – Closing It Down

It’s been a little while since I wrote about Azure.  Early on, I wasn’t sure how much I’d be focusing on using that outside of my day to day and the truth is, I haven’t touched it much since last year.  Nothing against the service, I just haven’t had a need for dedicated hosting in a while.
 
On that note, I will be shutting down my Azure resources as of today.  I’m in no rush to port what I’ve built so far to AWS, but my projects are on Github for any who are curious.  I may revisit them at a later date.
 
Even though I won’t be actively working in the Azure space for the foreseeable future, I’m still open to discussion and collaboration on the platform.  As always, if you have any questions or comments, please feel free to add them here or address them to john@benedettitech.com.

Thanks for looking in!

UI Unit Testing with Selenium – Part 4 – Selenium Server

 

Last time, I went over more advanced uses of Webdriver as well as putting together a framework of shared methods which can be hooked up to unit tests. For this last post, I’ll be standing up an instance of Selenium Server on Amazon Web Services and refactoring the test framework to point to that instance for testing.

What is Selenium Server?

Selenium Server is basically a hosted service that can accept and run Selenium tests independent of the actual testing client.  This allows for shared infrastructure that can be accessed by various clients without repeating the provisioning and setup of WebDriver files and other libraries.

For the provisioning of Selenium Server, I’ve decided to try out Amazon Web Services Elastic Computing service.  If you’re curious about AWS and want to take it for a spin, you can sign up for a free trial period that’s currently 1 year!  Information on EC2 and a link to sign up for the free trial is available at this link.

Standing up Selenium Server on AWS EC2

So first, I need a host.  After signing up for my free trial, provisioning an EC2 virtual machine using Windows Server only took a few minutes.

Then, I was able to copy over the Selenium Server JAR file and the Chrome WebDriver.exe.  Both of these can be found at the Selenium downloads page here.

Additionally, since the service is a Java Virtual Machine, I needed to install a Java Runtime Environment located here.

With my host, runtime and libraries in place, it’s time to start the service itself.  This involves a simple command line statement.  Elements show the location of the Chrome WebDriver on the EC2 host and I’ve also created a log file to keep track of any activity.

java -jar -Dwebdriver.chrome.driver=C:\ChromeWebDriver\chromedriver.exe C:\SeleniumServer\selenium-server-standalone-3.0.1.jar -log “C:\\SeleniumServer\SeleniumLog.txt” 

Refactoring the test project

Once the host is available, it’s just a matter of starting the host and telling the framework where it’s located.  This requires the download of an additional NuGet package called OpenQA.Selenium.Remote which gives you access to the RemoteWebDriver class.  Then I updated my Login and InternalLogin methods to use that as the framework’s IWebDriver object instead of the local one.

With these changes in place, my tests passed with flying colors.  While I chose not to run tests in anything but Chrome this time around, adding additional platforms for testing is as easy as adding the drivers to Selenium Server and then updating the DesiredCapabilities argument of the RemoteWebDriver object.

To wrap it all up, I committed my refactor to my SeleniumFramework repo on GitHub.  Please feel free to look at the updated version and pass along any feedback you might have.

Again, I hadn’t expected this series to take as long as it did, but it feels good to bring it to a close with some working code to show for it.  As always, if you have any questions or comments, please feel free to add them here or address them to john@benedettitech.com.

Thanks for looking in!

UI Unit Testing with Selenium – Part 3 – Advanced Webdriver & A Real World Example

Last time, I got into the basics of Webdriver and put together a couple of tests against ServiceNow.  For this post, I’m going to take a look at more advanced uses of Webdriver as well as putting together a framework of shared methods which can be hooked up to unit tests.  This involved going a little off script for the original course, but I think this series might be better served demonstrating application of the actual content rather than repeating it.

The goals that I have for this post will involve creating a new Solution with a Unit Test project as well as a Selenium framework class that can be reused within multiple tests.  Again, I’ll be testing against my private dev instance of ServiceNow, but I think it will be readily apparent how the framework could be extended as needed for other web frameworks.

I began by first creating a new testing project in Visual Studio, called SeleniumFrameworkTests.  Then I added the following tests based on the activities I demonstrated in the previous post.

LoginAsUser
LoginAsSuperUser
CreateIncidentAsUser
CreateIncidentAsSuperUser

I knew I’d want each test to be completely abstracted from the plumbing of ServiceNow, so I kept each test down to three arguments: environment, username and password.  The environment would hold the URL of the instance we’re connecting to.  And the username and password would contain those values for the account role needed to perform the tasks.  Lastly, I created an app.config file to hold the values.

testproject

Next, I created the main framework class called SeleniumFramework.  This framework class would need to include the Selenium and Selenium.Support packages from NuGet.  With that in place, I created the general Login method which accepts the environment, username and password arguments.  Then I copied the login steps from the previous post.  This allowed both the LoginAsUser and LoginAsSuperUser tests to pass.

loginmethod

The CreateIncident methods proved to be a little trickier.  First, each would require it’s own IWebDriver object with a valid login in order to proceed.  It made more sense to create a private method that returns an IWebDriver object for use by the CreateIncident methods.

privatelogin

With that in place, I copied in the CreateIncident steps from the previous post. The CreateIncidentAsUser test then passed but the SuperUser role has a different interface than the base User.  To get that test to pass, I had to create a separate method and tweak the UI names as needed for the test to then pass.

createincident

To wrap it all up, I created a new repo on Github called SeleniumFramework. Please feel free to take it for a spin yourself.   All you’ll need is a demo instance of ServiceNow as well as a copy of Visual Studio Community, both of which are free!

I know this series has taken much longer than I expected. However, I plan to close it out next time with an implementation of Selenium Server, most likely using the above testing project.

As always, if you have any questions or comments, please feel free to add them here or address them to john@benedettitech.com.

Thanks for looking in!

UI Unit Testing with Selenium – Part 2 – Webdriver Basics

Last time, I did a quick run-through of Selenium IDE for Firefox and got acquainted with the interface and commands associated with Selenium.  This time, I’m diving more into the meat of the framework and using Webdriver.

Webdriver is an API for that can be used by various languages (C#, Java, Python, & Ruby are some examples) that allows your tests to be maintained and run directly from code rather than using a recorder.  This allows us to take a more programmatical approach to testing rather than relying on the recorder exclusively.

We will be using Visual Studio for this example.  Firefox is supported right out of the box, but IE and Chrome require a special binary to be staged locally in order for those browsers to be used with Selenium.  This (and others) can be located via links at SeleniumHQ.

Since Chrome is my own preferred browser, I’m glad to move away from Firefox and experiment with something a bit more familiar.  I decided to start with rerunning the test that I created using Selenium IDE previously, then build on that a bit.

One feature that I didn’t mention about Selenium IDE, is the export function.  This creates source code in your chosen framework (C#, Java, etc.) from the Selenium markup code created by the recorder.

seleniumexport

One cool thing about the export is that it intersperses the markup within your code as comments.  This can be very useful when retracing what was done in a recording or for general documentation.

First off, I created a C# console project and installed the Selenium Webdriver plugin from NuGet.  With that in place, I’ve added the export from my previous post to a new project to test with Chrome.  My code is below:

using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
namespace WebDriverDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            IWebDriver driver = new ChromeDriver(@”C:\Libraries\”);
            driver.Navigate().GoToUrl(“https://dev20556.service-now.com/navpage.do”);
            driver.SwitchTo().Frame(“gsft_main”);
            driver.FindElement(By.Name(“user_name”)).Click();
            driver.FindElement(By.Id(“user_name”)).Clear();
            driver.FindElement(By.Id(“user_name”)).SendKeys(“USERNAMEGOESHERE”);
            driver.FindElement(By.Id(“user_password”)).Clear();
            driver.FindElement(By.Id(“user_password”)).SendKeys(“PASSWORDGOESHERE”);
            driver.FindElement(By.Id(“sysverb_login”)).Click();
        }
    }
}

This sample using the export from my previous post results in a successful login.  Now to build on it a little bit and create a test Incident:

            driver.FindElement(By.LinkText(“Incidents”)).Click();
            driver.SwitchTo().Frame(“gsft_main”);
            driver.FindElement(By.Id(“new_incident”)).Click();
            SelectElement urgency = new SelectElement(driver.FindElement(By.Name(“IO:5a33d0ef0a0a0b9b007b906f6c589c57”)));
            urgency.SelectByText(“1 – High”);
          driver.FindElement(By.Name(“IO:3f272c500a0a0b990059c24380a2bc02”)).SendKeys(“Creating a test incident.”);

            driver.FindElement(By.Name(“submit_button”)).Click();

Just adding these few extra lines results in a repeatable New Incident test.

incidentsuccess

It’s easy to start to see how this framework can be used to build a library of repeatable tests to automate QA and regression testing.

Link to the Full .NET API : http://seleniumhq.github.io/selenium/docs/api/dotnet/

As I continue to progress through the Pluralsight course, my next post should cover advanced WebDriver concepts and possibly Selenium Server.

As always, if you have any questions or comments, please feel free to add them here or address them to john@benedettitech.com.

Thanks for looking in!

UI Unit Testing with Selenium – Part 1


So, I’m making it through the Selenium Pluralsight course slowly but surely and I’m learning quite a bit so far.

The first part covers a browser plug-in called Selenium IDE.  Available only for Firefox, it’s essentially a session recording tool,  It records what we do in the browser then parses those into commands and then can be played back to act as tests.  To take this out for a spin, I went ahead and installed the plug-in and watched the demo on the course.  Now, we’ll need to find something suitable to test it on.

selenium

There’s a SaaS platform called ServiceNow that I’ve been spending a great deal of time in this year.  Automating testing against this platform from a central host is one of my goals for this experiment.  To test this out, I’ve created a test instance of ServiceNow and a test user.  Also, I’ve installed the Selenium IDE on Firefox so that I can record my session in the platform.

My demo is basically automating a login for my test user.  First I’ll need to create a fresh test case in Selenium.

newtest

Then, I’ll record the steps to the login to get a complete test.

finishedtest

Then I’ll run the test and see if it logs me into the system, which it does.

success

This is just scratching the surface of Selenium and I have more modules in the course to cover.  Next post, I’ll have some additional content from the next module (Selenium Web Driver) and possibly a little more.

As always, if you have any questions or comments, please feel free to add them here or address them to john@benedettitech.com.

Thanks for looking in!

UI Unit Testing with Selenium – An Experiment

It’s been a while since I’ve posted.  Part writers block and part outside obligations.  I know you’ve all been despondent and lost in the meantime.  Sorry about that. 🙂

Something that’s a recurring puzzle for me is adapting unit testing to MVC and SaaS solutions.   The challenges from my point of view are that MVC implies a lot of its functionality.  For example, things in MVC behave in very specific manners based on where they’re located or what they’re named.  Also, MVC classes (models) generally don’t have or need default constructors, so a traditional approach of instantiating a class an running business logic is insufficient.

Then, for SaaS solutions, you may not have sufficient access to the plumbing to build your tests directly, so you’re stuck automating a session through the SaaS provider’s interface and (hopefully) capturing the results that you need.  An approach to MVC might look very similar.

Enter Selenium

Either my Google-fu is weak in this space or there aren’t a lot of options for automating tests in this manner.  One framework that gets a lot of mentions is Selenium, so I’m going to take a stab at it.   I’ve found a few good blog resources but also remember that John Sonmez did a Pluralsight course that seems to be right up my alley.

My plan for this week is to watch the course and play around with the framework against a solution or two, then post about the results.  If the path seems promising, I’ll follow up with some additional content.

As always, if you have any questions or comments, please feel free to add them here or address them to john@benedettitech.com.

Thanks for looking in!

GameCareerGuide – Unity Platformer Tutorial

So, in keeping with the C# theme, I decided to take a stab at creating a small project in Unity and publishing it to Azure. To do this, I followed a tutorial provided by GameCareerGuide to create a simple platformer.

What is Unity? Unity is a popular game development platform that is free for individual developers contingent on revenue reaching a certain benchmark. (Currently $100K). You also have the option to buy a Pro subscription for $75 a month. I’m only at a stage where I’m tinkering around with the IDE and learning, so I’m not interested in paying for a sub if it’s not necessary.

unity

What is Game Career Guide?  GameCareerGuide is a site aimed at helping individuals who want to pursue a career in Game Development. There are various news items as well as links to resources and communities to help people launch or grow their careers. I came across the 2014 edition of their publication here and the tutorial I’m using begins on page 36.

gamecareer

Creating this was pretty straight forward. I had a copy of the 5.x version of Unity already installed and went through the steps in the tutorial creating various assets/objects to use in the game. One hurdle I ran into was needing to update the code as one of the base classes it relied on had been deprecated since the release of the guide. I was able to solve it using some simple cut & paste outlined in this article

deprecated

Next, I was having some issues committing the completed project to a Github repository. Something to do with how Github handles line breaks that can cause code corruption in some cases. Fortunately, updating the Github configuration for the new repo did the trick. I was able to use the Github CLI with the assistance of this article here to allow my code to commit. Even with the config change, my code built smoothly so I’m pretty sure there’s no risk.

After that, I created a new Web App node on my Azure account and used FileZilla to load my build via FTP. At first, the game was erroring out in both Firefox and IE so again I had to make a stop at the Googleverse. It seems that the site needed to provide a configuration item to allow the proprietary .unity3d file to download when you load the site. I was able to add the web.config file based on the following article

config

Finally, it was time to test out the game. Quite honestly, I’m a bit overly proud of taking these disparate platforms and making them work together. Plus it’s just neat to get something new to work, even if it’s trivial.

platformer

If you’re curious about the game, you can find it here . The controls are Left and Right Arrow and the spacebar and the object is to reach the yellow ‘exit’ square at which point the level resets. My son suggested that I might add some more levels and make it grow more difficult at each new level. Additionally, if you want to see the source code, you can find the repo on my Github account here.

If any of you are curious about or have used Unity or have any questions or comments, please feel free to add them here or address them to john@benedettitech.com.

Thanks for looking in!

Deploying a project to Azure

So, now that I’ve got all the Azure resources I need for the project, it’s time to actually deploy.  Again, following the instructions at Useful Development Blog, I’ll create the necessary objects in Visual Studio and then publish them to my Azure environment.

 
First, I’ll create the Web API project.  Since the article actually called for creating the resources inline with the project creation, I’ll actually skip the step where we create the Azure app itself.  Instead, I’ll just connect to the resources that are already there once the project is created.

CreateWebAPI

 
Second, I’ll install the Angular SPA package outlined in the article.  I am a complete Angular noob but am looking forward to tinkering with the framework as a lot of developers I know make great use of it.  Angular will install several dependencies such as jQuery.  Once this is installed, you can move on to the publishing step.

InstallAngular
Lastly, we’ll actually publish the newly created app ‘To The Cloud’.  You’ll go to the Publish dialog for your project and select Azure App Service to create a publishing profile.  I’ll look for the web app node previously created and ensure that it’s available for publishing.

PublishtoWebApp

WebAppValidation

 
Then I’ll add the connection criteria for the SQL database.  Please note, you will need to go into the Firewall settings for your Azure SQL Server and add your client IP in order to use SSMS or another tool to connect directly to the DB.  This includes the dialog for setting up the connection string for the app.  Once all your settings are in place, you can click Publish.

SQLConnection

PublishPreview

The publish may take a short while but once it’s complete, you can then navigate to the site and see the results.  If you’d like to take a look at mine, you can find it at http://jkbtestapp.azurewebsites.net/welcome

Finished

As you can see, once you get the hang of standing up the basic PaaS components, it’s very easy to deploy to an Azure environment. If any of you have suggestions around deploying to Azure or have any questions or comments, please feel free to add them here or address them to john@benedettitech.com.

Thanks for looking in!

How to Provision an Environment in Azure

It’s been a while since I’ve posted so I do apologize for the lag.  I’ve been doing some experimenting with Azure in my RL job and I’d like to share a couple of lessons learned with provisioning and deploying to Azure.

I was looking for an outline on simple deployments and found a quick walk-through at Useful Development Blog. Using this outline, I’m going to provision an environment and deploy a simple web app to Azure.

The prerequisites noted in the article are as follows:

* Visual Studio 2013 (Update 3+)
* The Azure SDK (you can get that here or use the Web Platform Installer)
* an account with Azure

I’m going to use the tools deployed previously to accomplish the same tasks. The only difference should be that I’m using Visual Studio 2015 Community rather than 2013.  Also, i’m going to provision my environment FIRST prior to deployment.  While you can automatically let Visual Studio create the necessary Azure nodes automatically in order to host your app, I feel that it will be necessary to know exactly what I’m provisioning and how much it will cost.

After reviewing the article, it looks like I’ll need a Web App node as well as a SQL database for the backend. In order to put all of this together, I’ll want to create the following resources:

* Azure Resource Group – This is a logical grouping of managed resources. It makes it easier to organize your nodes and identify which are related and dependent on each other. Also, in the event of any relevant notifications from Microsoft about impacts or changes to a region, you’ll want to know which one your resources are in.
* Azure Storage Group – This is a shared storage pool that can be used by any of your Azure nodes that require it.
* Azure Virtual Network – This isn’t truly required since we won’t be doing any network design or provisioning, but some of the nodes will require that one be set.
* SQL DB + DB Server – These will be PaaS (Platform as a Service) nodes to host my database.
* Web App – This will be another PaaS node to host the actual app.

I’ll begin by logging into the Azure portal and creating the Resource Group. You do this from your portal dashboard and clicking Resources Groups in the left sidebar then Add.  Choose an appropriate name, which subscription you want it to belong to, and where you want the Resource Group to be located.  The location may be relevant depending on where your customer base is for purposes of latency, etc.

RGCreation

Once the resource group is created, I’ll want to create a Storage Group. It can be more economical to use a shared storage group rather than many individual storage groups for each node. Additionally, you have more options for selecting the redundancy/fault tolerance of the storage as well as options for speed, etc.

To create the storage group, navigate to the Resource Group and click Add. A search window will pop-up where you can search for any of the myriad of nodes available in the Azure catalog. Select Storage Account and when prompted select Resource Manager for your deployment model and click Create.

CreateFromRG

StorageCreate

You’ll be prompted for the parameters to be used for your storage account. I will pick Locally Redundant and disable Diagnostics. Also, I’ll be selecting the Resource Group created in previous steps. When selecting your storage parameters, the amount listed for pricing is per month/100GB. You should only be charged for what you actually use so the cost should be pro-rated for the month.

StorageAccountParams

Next, I’ll create the Virtual Network. Follow the previous steps of navigating to your Resource Group and clicking Add. This time, type Network for your search criteria and select Virtual Network. As before, select the Resource Manager option and click Create.

For my parameters, I’ll be choosing an appropriate name and selecting my existing Resource Group and Location. Once this is selected, click Create.

NetworkParams

The next step, creating the SQL Server and DB, will be a bit more complicated but will follow the same basic pattern. As before, go to your Resource Group and click Add, then use SQL as your search criteria. The type of node you’ll select to create will be SQL Database. Once you’ve selected that option, click Create.

SQL DB Create

Inside of the SQL Database create panel, you’ll have an option to select your Server. Since we don’t have a server yet, our first step will be to create one. Click in the Server panel and then select Create a New Server. When creating a new server, you’ll choose an appropriate SQL Server name as well as creating your SA Account and password.  You’ll also select a location for the node.

SQL DB Params

SQL Server Params

Now that we have our Server, we can finish creating our DB. You can select an existing DB backup to map from or even use the sample Northwinds database. I’ll be selecting Blank DB for this example. There are a large number of pricing options to choose from for your DB performance and sizing options. Select the one that’s most appropriate for your app. Your subscription and Resource Group options should auto-populate. Once you’ve selected your options, click Create. The SQL DB creation takes a few minutes.

SQL DB Params 2

Lastly, we’ll need to provision a Web App node to host the actual app. Again, from your Resource Group, click Add and use Web App for your search criteria. Select the Web App option and click Create.

Web App Create

Once inside the creation dialog, you’ll choose an appropriate name for your app as well as confirm that your subscription info and Resource Group is correct. The last thing you’ll do is select a Service Plan. This is a configuration that can help you standardize your pricing and performance expectations for multiple apps. If you’re doing large scale or automated deployments, these can be useful to have for future tasks.

Under App Service Plan, click Create New.  Inside of the App Service plan creation panel, choose an appropriate name for the plan.  Under pricing options, you have various levels of availability and performance. Select the one most appropriate for you.  Again, rates are for the month and pro-rated for actual usage.  So, if you take your app down periodically or only need the services available at certain times, you can bring them down in the Azure portal and you should save that cost.

Web App Params

If you’ve completed all the above steps, then congratulations!  You’ve successfully provisioned your first Azure environment and are ready to deploy an app!

My next post will cover the creation of the project as well as the deployment steps.  If any of you have suggestions around provisioning in Azure or have any questions or comments, please feel free to add them here or address them to john@benedettitech.com.

Thanks for looking in!

Registering for an MSDN/Live Account and installing Visual Studio Community

In order to use my Azure trial, I’ll probably want a local copy of Visual Studio to build and publish content. In order to download Visual Studio Community (formerly Professional), I’ll need a Microsoft Live account eligible for the IDE. The good news is that in order to start my Azure account, I had to register a Microsoft Live account anyway. So, I’m halfway there.

Next step will be to log into Visual Studio with my live account: Link  Then click the Free Visual Studio option in the upper right and elect to join Visual Studio Dev Essentials.

VSDE

This brings up a page full of Microsoft tools. While I might have to come back to some of these later, right now I want to click the Download button under Visual Studio Community. This brings me to a download screen for the installer. Once that’s downloaded, I’ll run the setup.

DEHome

VSCdl

The setup wizard is pretty standard Microsoft boilerplate. Accept the defaults and next through. The wizard will install any dependencies your platform is missing, so you might be in for a bit of a wait and maybe a reboot or two. Once it’s finished, you’ll have the IDE installed and ready to go!

installwizard

Done

Another thing you’ll want for Azure is the Azure SDK. This has template for projects that are Azure specific as well as other useful plug-ins for Visual Studio. It can be installed at this link : Link  Select the SDK most appropriate to your installation. (VS 2015 for me)

SDKdl

One dependency that was required for my install was SQL Server Data Tools 2015.  This can be installed either by selecting custom options during your installation or by going back into the install wizard (Control Panel -> Programs & Features) and selecting the option.  As with all things, your mileage may vary depending on your environment.

SSDT

Once you have the IDE installed and are authenticated inside of Visual Studio, you will be able to publish content to Azure resources or nodes associated with your subscription.

If any of you have any questions or comments, please feel free to add them here or address them to john@benedettitech.com.

 
Thanks for looking in!