Scott Hanselman

NuGet Package of the Week: FluentAutomation for automated testing of Web Applications

March 4, '14 Comments [25] Posted in NuGet | NuGetPOW | Open Source
Sponsored By

FluentAutomation starting a testLast week I was exploring today's varied choices we have for Automated Browser Testing. There's headless WebKit "browsers" like PhantomJS and cloud powered multi-browser testing tools like BrowserStack and SauceLabs.

Selenium is kind of the gold standard and offers not only a lot of "drivers" but also a lot of language bindings with which drive a browser. Sometimes browsers update so fast there can be some version incompatibilities with Selenium, but for the most part it works great once you've settled in.

One option I've been looking at is FluentAutomation. It's a fluent automation API that supports Selenium as well as WatiN along with all their flavors and drivers. Since Fluient supports Selenium, that means you can use the Selenium ChromeDriver, IEDriver, Remote Web Driver or even the headless PhantomJS. FluentAutomation is on GitHub, of course, as well as on NuGet.

FluentAutomation has great (and growing) documentation and has adopted and interesting fluent style for it's API.

Now, not everyone likes a "fluent" API so it may take a while to get used to. Often you'll be doing things over many lines when it's really just one line, for example, this is one line:

I.Open("http://automation.apphb.com/forms")
.Select("Motorcycles").From(".liveExample tr select:eq(0)")
.Select(2).From(".liveExample tr select:eq(1)")
.Enter(6).In(".liveExample td.quantity input:eq(0)")
.Expect
.Text("$197.72").In(".liveExample tr span:eq(1)")
.Value(6).In(".liveExample td.quantity input:eq(0)");

Notice the method chaining as well as the use of CSS selectors.

FluentAutomation also has the cool concept of a PageObject to take your potentially brittle scripts and give them more structure. PageObjects group your actions, expectations, and assertions and let you reuse code when a page appears in multiple tests.

For example you could have a high level test (this is XUnit, but you can use whatever you want):

public class SampleTest : FluentTest {
public SampleTest() {
SeleniumWebDriver.Bootstrap(SeleniumWebDriver.Browser.Chrome);
}

[Fact]
public void SearchForFluentAutomation() {
new BingSearchPage(this)
.Go()
.Search("FluentAutomation")
.FindResultUrl("http://fluent.stirno.com/blog/FluentAutomation-scriptcs/");
}
}

Then you can have separate PageObjects that have your own public methods specific to that page, as well as assertions you can reuse.

public class BingSearchPage : PageObject<BingSearchPage> {
public BingSearchPage(FluentTest test) : base(test) {
Url = "http://bing.com/";
At = () => I.Expect.Exists(SearchInput);
}

public BingSearchResultsPage Search(string searchText) {
I.Enter(searchText).In(SearchInput);
I.Press("{ENTER}");
return this.Switch<BingSearchResultsPage>();
}

private const string SearchInput = "input[title='Enter your search term']";
}

public class BingSearchResultsPage : PageObject<BingSearchResultsPage> {
public BingSearchResultsPage(FluentTest test) : base(test) {
At = () => I.Expect.Exists(SearchResultsContainer);
}

public BingSearchResultsPage FindResultUrl(string url) {
I.Expect.Exists(string.Format(ResultUrlLink, url));
return this;
}

private const string SearchResultsContainer = "#b_results";
private const string ResultUrlLink = "a[href='{0}']";
}

You don't have to be all structure and OO if you don't want. You can just as easily write scripts with FluentAutomation and head in a different direction.

FluentAutomation along with ScriptCS = Automating your Browser with C# Script

I've usually used Python with my Selenium scripts. I like being able to just make a text file and start scripting, then run, debug, continue, all from the command line. It feels simple and lightweight. Creating a DLL and running Unit Tests in C# usually comes later, as I can move faster with a "scripting language."

You can do that with ScriptsCS as it gives you project-less C# that effectively is C# as scripting language. Combine this with FluentAutomation and you've potentially got the best of both worlds.

To install, first you need the Windows apt-get open source equivalent, the oddly-named and -spelled Chocolatey. Then you get ScriptCS and the packages for FluentAutomation.

  • Install Chocolatey - one line installation here
  • Run "cinst ScriptCS" from your command line to use Chocolatey to install ScriptCS
  • Now, get the ScriptCS script packages for FluentAutomation like this:
    • scriptcs -install FluentAutomation.SeleniumWebDriver
    • scriptcs -install ScriptCs.FluentAutomation

Now, as a quick test, create a folder and put a text file called start.csx in it with just these contents:

var Test = Require<F14N>()
.Init<FluentAutomation.SeleniumWebDriver>()
.Bootstrap("Chrome")
.Config(settings => {
// Easy access to FluentAutomation.Settings values
settings.DefaultWaitUntilTimeout = TimeSpan.FromSeconds(1);
});

Test.Run("Hello Google", I => {
I.Open(http://google.com);
});

Notice how there's no namespace, no classes, no main. It's just a script, except it's using C#. You can change the "Chrome" to "IE" or "Firefox" as well, to play around.

Random: I love this Selenium feature, exposed by FluentAutomation...take screenshot!

// Take Screenshot
I.TakeScreenshot("LoginScreen");

If you don't want ScriptCS, while it can act as a REPL itself, there is also the start of a dedicated FluentAutomation REPL (read–eval–print loop). This is basically a command prompt that lets you explore you app interactively and facilitates building your scripts. You can get the Repl as a Chocolatey package as well and just "cinst FluentAutomation.Repl"

You've got LOTS of choices in the world of automated testing. There's so many choices that there's just no good excuse. Pick a library, pick a language, and start automating your web app today.

Related Links


Sponsor: Big thanks to ComponentOne, a division of GrapeCity, for sponsoring the blog this week. Their widely popular .NET control suite, Studio Enterprise contains hundreds of data and UI controls such as grids, charts and reports that offer the functionality, features and support you need for current and future application development. Download your trial today!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Hanselman's Newsletter of Wonderful Things: January 21st, 2014

March 4, '14 Comments [1] Posted in Newsletter
Sponsored By

I have a "whenever I get around to doing it" Newsletter of Wonderful Things. Why a newsletter? I dunno. It seems more personal somehow. Fight me.

You can view all the previous newsletters here. You can sign up here to the Newsletter of Wonderful Things or just wait and get them some weeks later on the blog, which hopefully you have subscribed to. If you're signed up via email, you'll get all the goodness FIRST. I also encourage you to subscribe to my blog. You can also have all my blog posts delivered via email if you like.

Here's the Newsletter from January. Subscribers get the new one first. ;) 


Thanks again for signing up for this experiment. Here's some interesting things I've come upon this week. If you forwarded this (or if it was forwarded to you) a reminder: You can sign up at http://hanselman.com/newsletter and the archive of all previous Newsletters is here.

Remember, you get the newsletter here first. This one will be posted to the blog as an archive in a few weeks.

Scott Hanselman

(BTW, since you *love* email you can subscribe to my blog via email here: http://feeds.hanselman.com/ScottHanselman DO IT!)

P.P.S. You know you can forward this to your friends, right?


Sponsor: Big thanks to ComponentOne, a division of GrapeCity, for sponsoring the blog this week. Their widely popular .NET control suite, Studio Enterprise contains hundreds of data and UI controls such as grids, charts and reports that offer the functionality, features and support you need for current and future application development. Download your trial today!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

When is it stealing?

February 26, '14 Comments [89] Posted in Musings
Sponsored By

Image by Duncan Hill, used under Creative Commons from http://flic.kr/p/7YkGurAnything you put on the internet is gonna get stolen. It's preferable if it gets shared or linked to but often it gets copied and copied again.

RSS is magical but it makes it even easier to programmatically syndicate (copy) content. Search around and you'll likely find complete copies of your entire blog mirrored in other countries'.

There's so many websites (now "media empires") that have taken aggregation to the extreme, giving it the more palatable name "content curation." Now, to be clear, I respect the work involved in curation. Sites like http://dumbesttweets.com require work and attribute creators. But taking a post, copying unique content, even paraphrasing, and then including a small link just isn't kind. Forget about the legality of it, remembering IANAL, but it's just poor netiquette to not to ask permission before using non-Creative Commons content.

Every week or two I get an email from some large aggregation site that says "We'd love to reprint your post...it'll get you more readers." The few times I've done this they've gotten 50,000 views and I've gotten 300 referral views. Likely because the "originally appeared on Hanselman.com" link a the bottom is in 4 point font.

Sites like ViralNova and BuzzFeed are effectively reblogging and embedding machines powered by linkbait copyrighters. "What happened next will shock you."

Even if you make a piece of software, someone may just wrap/embed your installer with their own installer and build a whole business around it.

Narrating your blog posts

Today It was pointed out to me that a nearly 7 year old (and not very good) blog post of mine had be narrated - effectively turned into a podcast - by a startup called Umano. BTW, it's more than a little ironic that my post wasn't even mine. It's an excerpt - published with permission - of my friend Patrick Cauldwell's larger post.

I've used the Umano developer tools and embedded the narrated version here.

First, let me just say that this is essentially a great idea. It's the opposite of transcribing a podcast. It's creating podcasts from existing content using professional narrators, not just text to speech. This could be great for not just the visually impaired but also for anyone who wants to catch up on blogs while commuting.

UPDATE! Umano has narrated THIS blog post! Have a listen! http://umano.me/c/AExmo

Where did the Content come from?

Here's a screenshot of the post on Umano's site. You can see my name "Hanselman" is there, but it's not a link. The headline is a link, but you'd never know until you hovered over it. There's really no easy way to tell where, when, and how this content came about. I think that Umano could easily redesign this site to put the content owner front and center.

image

Podcasts and audio snippets from blog posts? Great idea, except I wrote the script for this podcast. If I wrote the script and they did the narration, then this must be a partnership, right?

However, if we look at Umano's own Terms of Use:

SoThree claims no ownership or control over any of the content you post to the Service ("Your User Content"). You or a third party licensor, as appropriate, retain all copyright, patent, and trademark rights to any of the content you post on or through the Service. You are responsible for protecting those rights.

Ok, they don't own the content.

By posting Your User Content on or through the Service, you grant SoThree a universal, non-exclusive, royalty-free license to reproduce, adapt, distribute and publish such content through the Service and for the purpose of promoting SoThree and its services.

I'm pretty sure I haven't granted them a universal license to my content as I didn't submit this link. On their home page they say that "you tell us what articles should be voiced." The community submits links, sometimes to content they are a fan of, but don't own, then Umano narrates it.

You may not aggregate, copy, or duplicate any SoThree Content.

Wait, but I can't copy their content? Their content that was generated from my content.

Does this mean I can get a book from the library and narrate it? Turn it into a podcast?

I am told by Umano's twitter account that I'm the first person to object to their content being copied without permission.

I certainly don't think Umano is are malicious. Umano is perhaps naive, if they think can narrate blogs without someone speaking up. That said, their narrators are top notch and their site and app are both attractive and usable. Frankly, I'd be happy if they narrated my whole blog (or at least the good stuff and not the lousy decade-old stuff) and made a podcast feed of my blog like their competitor Castify. But I'd like Umano to do it with me.

Sites like this should ask creators first and their business model should be based on partnerships with content creators, not assumptions. Stitcher has the right idea. I've submitted my content to them and entered into a partnership. They didn't just suck my podcasts in and make a radio station.

Even a single email from Umano like "hey, we would love to narrate your blog, click here and sign this little form" would have be sufficient. 

Narrate first, ask questions later? Michael Dunbar nails it with this tweet:

This is an easily solved problem, and it's not just a problem with Umano. This applies to all businesses and startups that rely on content created by others. I think it's important to honor attribution. This isn't about money or even copyright, although those things do apply. Rather, this is about netiquette. When you're building a business model, build it around partnerships and transparency, not assumptions around fair use and copyright. Aask first.

What are your thoughts, Dear Reader?

(If they narrate this one, I'll update the post and complete the circle. ;) )

Related Links

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Announcing the new Roslyn-powered .NET Framework Reference Source

February 24, '14 Comments [40] Posted in Musings
Sponsored By

.NET Framework Reference Source SiteIn 2007 ScottGu's team announced they were releasing the .NET Framework source code for reference. Just a little later, Microsoft made it possible to step through the .NET Framework Source code while debugging. This was announced to much fanfare, and for a while, it was very cool. It wasn't "Open Source" but it's definitely "Source Opened."

However, as time passed, the original Reference Source website for the .NET Framework sucked for a number of reasons, mostly because it wasn't updated often enough.

Fast forward to today...we're back and the .NET team is launching the fresh new and updated .NET Reference Source site with a Roslyn-powered index!

The new beta site is at http://referencesource-beta.microsoft.com and it'll move over to replace the existing http://referencesource.microsoft.com site soon.

It's easy to browse the code, but if you'd prefer you can also download the .NET Framework source in a ZIP from the download link at the top of the site.

The Roslyn-powered .NET Reference Source browser

There's some very cool .NET-related stuff happening this year, and you'll be hearing about it all soon. The new "Roslyn" compiler-as-a-service replacements for the C# and VB compilers have had the "Big Switch" flipped. We're now getting an amazing totally-rewritten managed compiler that can enable features that weren't possible when .NET started over a decade ago.

Today there's a new team working on the .NET Reference Source, and Roslyn let the team generate a complete syntactic and semantic index of the .NET Framework Sources.

From the team: The version of the framework that we currently have indexed is .NET framework version 4.5.1.  If this is something that folks agree is useful, our ongoing commitment towards this feature is to update this every major release i.e. an update for 4.5.2 and so on.  

This is a crucial feature, IMHO, and they are recommitted to making it happen, and most importantly, keeping it fresh and updated. They are also thinking about maybe using the Monaco editor for the site as well.

Be sure to explore the browser and click on everything, as there's a lot more there than just "search box and results."

Here's a few cool things you can do with the URLS on the new site that you should explore. I like being able to reference a line number in the URL for tweeting or IM'ing.

There's also a lot of flexibility in the search:

You can also actually click on types directly within the editor and find where they are referenced in the code.

clip_image002

They will switch the beta site at http://referencesource-beta.microsoft.com/ to take over the existing Reference Source site soon. Until then, use the Feedback link on the site and email the team directly! They are listening and actively working on this site.

The next thing the team is working on, and they are very close, is getting .NET Source Stepping (meaning you can just F11 into the .NET source code) to again work reliably when debugging, no matter what patch version you have of the .NET Framework on your local machine. Look for that in a few days on the .NET Team Blog.

BONUS: Community Visual Studio Extension

Here's an exciting bonus. Community member and fabulous coder Schabse Laks has created a Visual Studio extension for VS2010, 2012, and 2013! This extension sends calls to Go To Definition (or pressing F12 on a symbol) directly to the code online (when it's .NET Framework code, not yours).

You can download this companion "Ref12" Visual Studio Extension now! Just Goto Definition on any .NET type we have source for and it'll launch your default browser so you can explore the .NET Framework source yourself! Thanks Schabse!

.NET Reference Source Code Licensing Clarified

Finally, the licensing before was originally the very straightforward Microsoft Reference Source License,  but then started to get other caveats tacked on like "don't look at this if you aren't using Windows" until it wasn't really the MS-RSL at all.

They've changed that stuff. They're back to the straight MS-RSL which is easy to read and clear. This means that folks can now look at this Reference Source and not have to gouge their eyes out afterwards. Which is great!

We all hope you like the new site and the team looks forward to your comments!


Sponsor: Big thanks to Red Gate for sponsoring the blog feed this week! Easy release management: Deploy your SQL Server databases in a single, repeatable process with Red Gate’s Deployment Manager. There’s a free Starter edition, so get started now!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Microsoft killed my Pappy

February 22, '14 Comments [327] Posted in Musings
Sponsored By

Photo by Frank Swift used under Creative CommonsI was talking to a young (<25) Front End Developer recently who actively hated Microsoft. Sometimes I meet folks that are actively pissed or sometimes ambivalent. But this dude was pissed.

The ones I find the most interesting are the "Microsoft killed my Pappy" people, angry with generational anger. My elders hated Microsoft so I hate them. Why? Because, you wronged me.

"You killed my pappy," said the youth, "and my pappy's pappy. And his pappy's pappy. And my brothers Jethro, Hank, Hoss, Red, Peregrine, Marsh, Junior, Dizzy, Luke, Peregrine, George and all the others. I'm callin' you out, lawman."

One person said that he was still mad about the Microsoft Anti-Trust thing. "Hey, 10 years ago Microsoft did this..." That was initiated in 1998 for actions in 1994. That's 20 years ago.  And for bundling a browser in the operating system that couldn't be uninstalled or easily replaced? Sure, no operating systems do that in 2014. I wonder if I can swap out Chrome from Chrome OS or Mobile Safari in iOS. Point is, it's common now.

This "generational technology pain" seems to persist long after the root causes have died. Do I hate Japan for World War II? My 6 year old wanted to know this as he's learning world history. I said, "No, we're cool with Japan. We've done some good stuff together." And he was like, "Cool." 

I realize that you, Dear Reader, are a thoughtful and respectful lot, the Internet tends to be a bit of a motley crew. I fully expect the comments to be on fire later. But know this, I didn't work for The Man when all this went down, and I was as outraged as you were 20 years ago (assuming you were alive). But now, I've been here pushing open source and the open web for over 5 years and things are VERY different. I know you all have stories about how you were wronged, but we all have those about various companies. You're pissed about IE6, about FoxPro, about Silverlight, heck, maybe VB6. Sure, I hear you. I'm pissed about DESQView and my Newton, and Snow Leopard not running on my PowerPC. At some point you let go, and you start again with fresh eyes.

Embrace, Extend, Hugs?

We're putting source on GitHub, many groups are using Git with TFS internally for projects, we've open sourced (not just source-opened) huge parts of .NET and are still pushing. We've open sourced Azure hardware specs, opening SDKs, and we're making systems more pluggable than ever. Frankly, we're bending over backwards to NOT be dicks about stuff, at the very least in my corner of the company. Could we do better? ALWAYS. Are we pure evil? Nah.

Is Microsoft circa 2014 worse than Google, Apple, or Facebook? We're not nearly as organized as we'd need to be to be as evil as you might think we are.

Moreover, I think that Microsoft is very aware of perceptions and is actively trying to counter them by actually being open. I'd say we're more concerned than a Google or Apple about how folks perceive us.

I don't speak for Microsoft, I'm not a mouthpiece or a marketer. Sure, I promote the stuff I work on, because some of it is damn cool stuff. I'm a programmer with a blog who likes to speak on technology. But I am not my employer.

That said, I will quote myself (again, opinion, don't fire me) from my own Hacker News comment regarding the direction we're going:

It's worth noting that under Satya [Ed: And ScottGu] (in my org, Cloud and Enterprise) we open sourced ASP.NET, use 50+ OSS libraries in Visual Studio, have all the Azure cloud SDKs on GitHub, and on and on. We made Portable Libraries happen and now share code between iOS, Android, and Windows. This is not your grandfather's MSFT, and now the dude who helped us (Azure) change things in a fundamentally non-MSFT and totally awesome way is in charge. I'm stoked - big things coming, I think.

Sure, we do stupid stuff sometimes, usually because someone in one org isn't talking to another org, or some marketing vendor overreaches, every big company makes these mistakes.

But I like the direction we're heading. I work here to fix stuff. Some folks complain, some tweet complaints, I'm here to fix it. If it was a lost cause, I'd quit, as I truly don't need the job that badly. I'm happy to be a small part of a small part of pushing us. I will push until I can't push anymore.

I said, find a new reason to hate Microsoft. I didn't kill your Pappy, son.

* Photo by Frank Swift used under Creative Commons


Sponsor: Big thanks to Red Gate for sponsoring the blog feed this week! Easy release management: Deploy your SQL Server databases in a single, repeatable process with Red Gate’s Deployment Manager. There’s a free Starter edition, so get started now!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.