Back in December, I wrote this post about my efforts to set up automated testing on an iPad in MonoTouch. I updated that a couple of weeks ago, noting that there was now a --launchdev option which might make all of that unnecessary, so long as your test app didn't need any data. Unfortunately, mine did. However, as of MonoTouch 5.2.5 (or potentially earlier, but 5.2.5 is when I noticed it), I saw a new command-line option appear for the mtouch program: --argument. It's description? "Launch the app with this command line argument. This must be specified multiple times for multiple arguments." Could this be a way I could ditch the separate launcher app and related AppleScript incantations completely? The short answer is yes. The long answer follows, after the break.
Friday, March 2, 2012
Automated Testing with MonoTouch on an iPad: Revisited
Saturday, February 18, 2012
C# Initializers
C# generic collections offer a lot of flexibility and power for organizing your program's data. However, if you need to set one up manually, you may have written code that looks something like this:
List<string> list1 = new List<string>();
list1.Add("list1 item1");
list2.Add("list1 item2");
list2.Add("list1 item3");
List<string> list2 = new List<string>();
list2.Add("list2 item1");
list2.Add("list2 item2");
list2.Add("list2 item3");
List<string> list3 = new List<string>();
list2.Add("list3 item1");
list2.Add("list3 item2");
list2.Add("list3 item3");
Dictionary<string, List<string>> dictionary = new Dictionary<int, List<string>>();
dictionary.Add("list1", list1);
dictionary.Add("list2", list2);
dictionary.Add("list3", list3);
Wouldn't it be nice if you could declare a dictionary in one statement? Or a list? Or an array? Or even an entire class, complete with all data members, which may themselves be other classes, lists, dictionaries, or arrays? Well, turns out that you can. Find out how after the break!
Friday, February 17, 2012
Customizing Appearance of Disabled UIBarButtonItems
Have you ever wanted to change the appearance of a disabled UIBarButtonItem? It seems to be a fairly common issue without many good solutions - at least, until iOS 5.0, anyway. Perhaps you've tried this one:
UIBarButtonItem button =
new UIBarButtonItem("Untitled 1", UIBarButtonItemStyle.Plain, null);
button.TintColor = UIColor.White;
button.Enabled = false;
It all works fine, up until you disabled the button, at which point your button becomes a very faded version of whatever you had in there. Normally, that's what you want to have happen, because dimming the button is a good indication to the user that the button cannot be pressed at the current time. However, there may be situations where that isn't true...
For example, I have a toolbar with a document title in the center. It's a UIBarButtonItem, so that it can detect touches, and respond by showing a UITextField that allows the document title to be edited. The document editor has two modes: an edit mode, and a run mode. In run mode, I don't want the title to be edited, so I disable the button. However, I still want it to be nice and visible, like a title should be. I also wanted to avoid the obvious workaround of swapping out my title button for another non-functional button with the same content. It would work, but it would kind of break some of the behind-the-scenes stuff we're doing with our user interaction model, and would require me to maintain the state of two separate buttons with the title. Also, a button that is enabled has a little sparkly animation when it is touched, to let you know that it is touchable and that the system recognized that you touched it. The two-button workaround means I would still have that animation, and gives the user the impression that they can still edit the title, but it's not working right.
So, what did I do? Find out after the break.
Sunday, January 29, 2012
Web Form Automation with Selenium WebDriver
Have you ever had a tedious task involving a web site form that you have wanted to automate, but couldn't? Or perhaps you wanted to automatically test a website you were making? Well, there's a fairly well-known tool for browser automation called Selenium. I'd heard of it before, and was looking into it when I had a project where I want to take some JavaScript based pages, run them through a JavaScript engine so they could generate the HTML I needed and then save the results. But until now, I had never had a chance to use it. It's powerful, and there's a lot you can do with it that I won't cover. But the basics will get you a long way.
More after the break.
Saturday, January 21, 2012
Composing Emails and Sharing Files in MonoTouch
Lately, I had to add the ability to import and export data from a MonoTouch application via email. Thanks to everything you get in the iOS SDK for free, this is actually relatively easy. But you do need to know all the places you need to touch to make this happen. You'll need to:
- Modify your info.plist to specify the file types your application supports
- Update your application delegate to override the HandleOpenUrl method
- Update your view controller to show a mail composer
- Add code to your view controller to import a file that is passed to it and display it
Many thanks to this this tutorial on email sharing to get me going on this.
Details after the break.
Sunday, December 18, 2011
Redirect Console Output in C#
I've been writing some tools that will duplicate behavior that I get for free in Visual Studio's MSTest framework for MonoTouch. One of the last pieces of the puzzle was the fact that MSTest will log any output to the console as part of the test results XML file. However, it does it intelligently, so that the output for each test is saved with the test results, and any output that is emitted outside of a test goes to the console. So, how could I redirect console output temporarily?
