Selecting by Option Value using Capybara

Capybara’s select command allows searching a HTML select field and selecting an option that matches the supplied value by name, id or label text. Additionally, the match option allows the user to indicate the behaviour if more than one option is found. For example, match: :first will select the first item out of multiple matches, while match: :one will throw an error if more than one item is found.

I was recently dealing with a time zone select list based on ActiveRecord::TimeZone. I was receiving an error when Capybara tried to select “Samoa” from the option list (“Samoa” due to test randomisation), since there were items named “American Samoa” and “Samoa”. I ended up having to select the option via its ‘value’ attribute instead:

time_zone = ActiveRecord::TimeZone.all.sample
find('select#time_zone').find("option[value='#{time_zone.name}']").select_option

Auto-Mounting VirtualBox Shared Folders with a Linux Guest OS

VirtualBox has a feature where a folder on the host machine can be shared with a guest VM. VirtualBox can also mount these shared folders automatically when the user logs into the guest OS. For Linux guests, these auto-mounted shared folders are mounted into the /media directory, along with the prefix sf_. For example, the shared folder sharedfiles will be mounted to /media/sf_sharedfiles.

As only the user group vboxsf is granted permissions to the auto-mounted shared folders, you’ll need to add your user to the group to access the shared folder. Otherwise you’ll get a “Permission denied” error when trying to navigate to the shared folder.

sudo gpasswd -a username vboxsf

Make sure you log out of the guest OS, then log in again for the group membership to take effect.