Selenium

OK, one more post for tonight. (This is another one I suspected that I may have previously written up, but apparently not.)

I’ve known about Selenium for awhile now, mostly because one of our clients has a “testing guy” and he uses it. I’ve always wanted to be able to do some automated testing of web site projects, but it always seemed like the tools for doing so were too limited or complex. I’ll admit I put off downloading & learning Selenium, largely because I thought it would be a hassle and eat up a lot of time before I could really do anything useful with it. When I finally gave it a chance, though, I was surprised how easy it was to use.

I initially started with WebDriver, which is basically a couple of DLLs that let you “drive” Firefox (or another browser), sending keystrokes and click events, and looking for certain responses. You can get started with WebDriver quickly by grabbing it via NuGet. My first project with WebDriver was a simple console program that launches Firefox, then goes to several of the store locator web sites that use our Bullseye API, does a search at each one, and checks to see if it gets results. Nothing big, but just a useful program that I can run any time I roll out code changes to the API. Previously, I’d been checking this stuff by hand after each rollout.

Today, I took another step, and downloaded Selenium IDE. This is a Firefox plugin that lets you record a series of actions as you do them, then save them to a script. There are plugins allowing you save the script in several languages, including C#. So, I can record some steps, export some C# code, then fix it up to do some reasonable testing. My main purpose today was to record the steps involved in a fairly complex workflow on one of our client sites. It’s a multi-step process (around 20 steps, I think). Just in and of itself, the script is useful to have, as I often need to step through it to establish a new test account, so now I can just “play” it instead of clicking through the whole process myself. But, I would also like to use it to automate some testing of this process. Now that I have a base script, I can go in and replace the values I entered today with variables, so I can abstract things out in such a way that I can run the code repeatedly, testing multiple scenarios. And since I can do this all in C#, I can also then check the database, and see if the values I entered were interpreted and stored in the database correctly.

This may all seem pretty routine to some people, but I have to admit that I’ve never really had a chance to do this kind of testing before. It’s kind of cool!

I think my next project is going to have to be trying WebDriver with browsers other than Firefox.  I’d like to be able to test the same workflow in IE, Firefox, and Chrome, at least. (And if I get really ambitious, maybe I’ll see about iOS browser automation…)

xdebug

I thought I’d written up an entry on Xdebug for PHP a while ago,  but apparently not. (Or, if I did, it’s not coming up when I search for “xdebug” for some reason.) Anyway, Xdebug is a debugging tool for PHP. It’s definitely worth enabling, if you’re doing anything with PHP that’s in any way non-trivial.

It’s a bit hard to figure out the best way to get started with it under Windows. It turns out to be pretty easy, though, given a few pointers. First,  go to the wizard page, and paste in the contents of a phpinfo() call, run on the machine you’re installing to. This will then tell you exactly which file to download, where to put it, and what to add to your php.ini. Much easier than trying to figure that stuff out yourself!

A few other pointers:
– Depending on how you download & copy the DLL over, you may need to unblock it. (Blocked files really annoy me, by the way. I don’t know whose idea that “feature” was, but it was not a *good* idea. See here for some ways to unblock multiple files easily.)
– Xdebug can add color to your var_dump() calls. Add “set html_errors = On” to your php.ini to enable this. I’ve found it to be very helpful when looking at a complex object. (Of course, there’s always krumo for that too.)
– To get debugging working under Komodo IDE, take a look at this document. One thing that was confusing to me was that debugging locally is still considered “remote debugging”.

Also, on a related note, I’m not sure I ever mentioned that, after looking at a few options, I settled on Komodo as my PHP IDE of choice. It’s reasonably fast and easy to use, and the debugger works pretty well. There are a few things about it that I’m not too fond of, but overall, it’s really good.

Drupal Rules

I haven’t blogged in a bit, and I have a few random items I want to write up. I’m doing a lot of work with Drupal, and I’m still learning some little tricks here and there.

When I’m writing custom code, I often use Drupal’s cache. That’s pretty easy to do, with cache_set and cache_get. I recently found myself in a situation, though, where I wanted to clear a certain item from cache any time a user created or edited a node of a certain type.

It turns out to be really easy to do that with the Rules module. Just set up a rule that is triggered on insert or update of a certain node type, and make the action a simple line of PHP code:

cache_clear_all(‘your_cache_key’, ‘cache’);

Easy!

another failed Windows 8 upgrade attempt

I took another shot at upgrading my desktop PC to Windows 8 today. I first uninstalled some software that I thought might be causing problems, then ran the upgrade using the “just personal files” option. I figured this would wipe out the Windows and Program Files folders, and leave me with a clean Windows 8 install. The plan would then be to re-install all the software I would need, under Windows 8. Good plan, but once again, the install failed and rolled me back to Windows 7.

I’m really not sure what’s going wrong. I have a few ideas, based on stuff I’ve found in the Windows 8 install forums, but I’m not sure what’s likely to work and what’s not. Since the install/restore process takes about two hours, I think I’m going to have to wait a bit before trying the upgrade again.

Windows 8 upgrade failed

So my ill-considered attempt to upgrade my desktop machine to Windows 8 failed. The computer seemed to blue-screen after the install finished (showing the silly new Win 8 error screen), then rebooted to a screen telling me that the upgrade failed, and that it was restoring my previous Windows version. Surprisingly enough, that worked well, and I’m right back where I started.

I had originally only intended to run the upgrade advisor, and not actually do the upgrade. But, when I ran setup.exe from the DVD, it went straight into the upgrade, without giving me any indication of software incompatibilities or anything like that. I was going to cancel the install, but I decided to give it a shot anyway. I guess that wasn’t really a good idea.

So, with the computer back to Windows 7, I started poking around on the DVD to figure out how to run the upgrade advisor. I didn’t actually find it on the DVD, but I managed to download it from Microsoft and run it from there. There are actually a number of things on the computer that won’t work in Win 8, and that need to be either removed or upgraded. I’m not sure which of those might have been serious enough to have screwed up the install though, or if the problem might be with something else entirely.

Well, I’m going to try to take care or removing and upgrading stuff, then maybe take another shot at the upgrade next weekend.

Sandy follow-up and more

I got cable service back yesterday, so I’m pretty much back to normal, at least as far as utilities are concerned. My goals for today were modest — I just wanted to get my laundry done, pay some bills, run a couple of errands, and then relax and watch some TV.

At work, over the last couple of days, we’ve been working on a web site to allow people to search for open gas stations in the area. Getting gas has been a huge problem here in NJ since the storm. The web site is live at http://findgas.org/ now. Unfortunately, it’s been popular enough that we had to make some adjustments, lest the site take down our main web server. Not really what I wanted to be doing today, but not a big deal either. In hindsight, we should probably have put the thing up on AWS, on a self-contained EC2 instance. Live and learn, right?

Meanwhile, I decided to take a shot at upgrading my main desktop computer (here at home) to Windows 8. I was originally going to go through and uninstall some old software first, but in the end, I decided to just start the upgrade and hope for the best. I didn’t even do a backup first, which is something I may regret later. Either way, it’s running right now. Previous experience from my laptop upgrade would lead me to believe that it’ll take an hour or two to finish.

Sandy

Just a quick post to say that my section of Main St in Somerville got power back at around 9pm last night. I’d lost power on Monday night, at around 9pm, so that was three days with no power. I know a lot of places got hit much worse that Somerset County. It was weird living without electricity for three days though.

My iPhone and iPad kept me connected. Both Verizon (iPhone) and AT&T (iPad) 3G stayed up most of the time. (AT&T disappeared for several hours at one point, but I never had a problem with the Verizon service.)

My cable service isn’t back up yet, so no high-speed internet at home just yet. Hopefully soon!