Pages

Sunday, December 4, 2016

Selenium IDE, C# Visual Studio, and MSTest

Within Visual Studio Package Manager install packages


Within Visual Studio package manager

  •     Install-Package Selenium.RC (optional)
  •     Install-Package Selenium.WebDriver
  •     Install-Package Selenium.WebDriverBackedSelenium
  •     Install-Package Selenium.Support

Or, download zip file from: Selenium Webpage

    Extact zip file.
    Within Visual Studio add reference to these dlls

  •     Selenium.WebDriverBackedSelenium.dll
  •     ThoughtWorks.Selenium.Core.dll
  •     WebDriver.dll
  •     WebDriver.Support.dll

Now, Visual Studio has reference Selenium

Download the Internet Explorer Driver Server from: Selenium Webpage


    Download should be a single .exe file: IEDriverServer.exe

    Very Important that the IE Driver is able to find IEDriverServer.exe


  • Move IEDriverServer.exe into MS Test project's bin\debug folder
  • Or, make sure IEDriverServer.exe absolute path is added to the Path environment variables.

Start > right click Computer > properties > Advance system settings


Environment Variables > scroll down to Path > Edit > add, at end of text, the folder's absolute path where IEDriverServer.exe is found.

 
Install Selenium IDE Firefox plugin


After installing plugin, open Firefox, click on Tools > Selenium IDE

 

Using Selenium IDE, record some actions by clicking IDE's record button.


Export as C# / NUnit / WebDriver and save into project's folder



Generated NUnit Test Class


After changer were made


Must Include reference to
  • Microsoft.VisualStudio.TestTools.UnitTesting
in projects.




Within Visual Studio, create a Unit Test Project




    Remove UnitTest1.cs file





This post is for the purpose of my notes only and sometimes a rant.

“I invented nothing new. I simply assembled the discoveries of other men behind whom were centuries of work. Had I worked fifty or ten or even five years before, I would have failed. So it is with every new thing. Progress happens when all the factors that make for it are ready and then it is inevitable. To teach that a comparatively few men are responsible for the greatest forward steps of mankind is the worst sort of nonsense.”
Henry Ford

Monday, October 10, 2016

ASP.NET Bundling Rendering Media Attribute on Link Tag


Reading this post about making a site mobile friendly, I noticed ASP.NET bundling doesn’t render the media attribute on the HTML link tag.

Quick search, found a solution at stackoverflow:


From the posted solution, I changed it a little.

<!DOCTYPE html>

 

<html class=" js ">

<head>

    <title></title>

    @Styles.Render("~/Styles/Base")

</head>

<body class="master-body" id="index">

To…

@using com.dogPedaler.Models

 

<!DOCTYPE html>

 

<html class=" js ">

<head>

    <title></title>

    @Styles.RenderFormat(BundlesFormats.Screen, "~/Styles/Base")

</head>

<body class="master-body" id="index">



The change includes the namespace to a class with a static property call Screen:

@using com.dogPedaler.Models

The Created Class

namespace com.dogPedaler.Models

{

    public class BundlesFormats

    {

        private const string template = @"<link href=""{0}"" ";

        private const string template2 = @"rel=""stylesheet"" type=""text/css"" media=""{0}"" />";

        public static string Print

        {

            get

            {

                return template + String.Format(template2, "print");

            }

        }

        public static string Screen

        {

            get

            {

                return template + String.Format(template2, "Screen");

            }

        }

        public static string HandHeld

        {

            get

            {

                return template + String.Format(@"rel=""stylesheet"" type=""text/css"" media=""print"" />", "handheld");

            }

        }

 

    }

}

Notice three properties

  • print
  • Screen
  • handheld

There is a reason why the “S” is capitalized. This is a hack for Windows mobile browsers and can be found at:

https://perishablepress.com/the-5-minute-css-mobile-makeover/
 
 
This post is for the purpose of my notes only and sometimes a rant.

“I invented nothing new. I simply assembled the discoveries of other men behind whom were centuries of work. Had I worked fifty or ten or even five years before, I would have failed. So it is with every new thing. Progress happens when all the factors that make for it are ready and then it is inevitable. To teach that a comparatively few men are responsible for the greatest forward steps of mankind is the worst sort of nonsense.”

Henry Ford

Thursday, September 29, 2016

MVC Setup from Empty ASP.NET template

ASP.Net Empty template doesn't have any nuget packages included, so no packages.json will exist.

1. Installing MVC

Packages Icluded

Microsoft.AspNet.Mvc

Microsoft.AspNet.WebPages

Microsoft.AspNet.Razor

Microsoft.Web.Infrastructure   

References Installed

System.Web.WebPages.Razor

System.Web.WebPages.Deployment

System.Web.WebPages

System.Web.Razor

System.Web.Mvc

System.Web.Helpers

Microsoft.Web.Infrastruture

2. Uninstall-package - References Removed

Microsoft.AspNet.Mvc

System.Web.Mvc

Microsoft.AspNet.WebPages

System.Web.WebPages.Deployment

System.Web.WebPages

System.Web.Helpers

Microsoft.AspNet.Razor

System.Web.Razor

Microsoft.Web.Infrastructure

Microsoft.Web.Infrastruture

Finial complete MVC directory structure:

3. Add Global Application Class File to application

Global.asax.cs

Project right click > Add > New Item… > Select Global Application Class

4. Create folders

·         App_Start (can named anything)

·         Controllers

·         Views

5. Under App_Start create a class file and name it whatever you want - RouteConfiguration.

.axd file types are HTTP Handlers, which should be ignored.

Add code to file:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.Mvc;

using System.Web.Routing;

 

namespace myWebsite.App_Start

{

    public static class RouteConfiguration

    {

        public static void Register(RouteCollection routes)

        {

            routes.IgnoreRoute("{resource}.axd/{*pathinfo}");

 

            routes.MapRoute(

                "Default",

                "{controller}/{action}/{id}",

                new { controller = "Home", action = "Index"}

                );

        }

 

    }

}

 

6. Add code to Global.asax class file passing all routes.

using com.waggintails.App_Start;

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.Routing;

using System.Web.Security;

using System.Web.SessionState;

 

namespace com.waggintails

{

    public class Global : System.Web.HttpApplication

    {

 

        protected void Application_Start(object sender, EventArgs e)

        {

            RouteConfiguration.Register(RouteTable.Routes);

        }

    }

}

7. Within controllers folder, add a MVC5 Controller - Empty

Rename to whatever you like – Home

Add code to file:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.Mvc;

 

namespace com.waggintails.Controllers

{

    public class HomeController : Controller

    {

        // GET: Default

        public ActionResult Index()

        {

            return View();

        }

    }

}

 

8. Within views folder, add an empty view and name the view as the same name that you had for the controller.

Add code to file:

@{

    ViewBag.Title = "Home";

}

 

<h2>Home</h2>

 

And within Views folder, add a web.config file.

Add code to file:

<?xml version="1.0"?>

 

<configuration>

    <configSections>

        <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">

            <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />

            <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />

        </sectionGroup>

    </configSections>

 

    <system.web.webPages.razor>

        <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

        <pages pageBaseType="System.Web.Mvc.WebViewPage">

            <namespaces>

                <add namespace="System.Web.Mvc" />

                <add namespace="System.Web.Mvc.Ajax" />

                <add namespace="System.Web.Mvc.Html" />

                <add namespace="System.Web.Routing" />

                <add namespace="com.waggintails" />

            </namespaces>

        </pages>

    </system.web.webPages.razor>

 

    <appSettings>

        <add key="webpages:Enabled" value="false" />

    </appSettings>

 

    <system.webServer>

        <handlers>

            <remove name="BlockViewHandler"/>

            <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />

        </handlers>

    </system.webServer>

 

    <system.web>

        <compilation>

            <assemblies>

                <add assembly="System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

            </assemblies>

        </compilation>

    </system.web>

</configuration>

Press F5 and Home view should show correctly

9. <Optional> Include a layout view

Within the Views directory add a view called

_ViewStart.cshtml

This view allow you to specify the path for the layout view.

Add code:

@{

    Layout = "~/Views/Shared/_Layout.cshtml";

}

Within the directory you had specified in _ViewStart, add the specified view -  _Layout.cshtml

Add code – when using layouts, must include @RenderBody.

<!DOCTYPE html>

 

<html>

<head>

    <meta name="viewport" content="width=device-width" />

    <title>_Layout</title>

</head>

<body>

    <div>

        @RenderBody()

    </div>

</body>

</html>

With layout, finial complete MVC directory structure:




This post is for the purpose of my notes only and sometimes a rant.

“I invented nothing new. I simply assembled the discoveries of other men behind whom were centuries of work. Had I worked fifty or ten or even five years before, I would have failed. So it is with every new thing. Progress happens when all the factors that make for it are ready and then it is inevitable. To teach that a comparatively few men are responsible for the greatest forward steps of mankind is the worst sort of nonsense.”
Henry Ford