Creating Mac Keyboard Shortcuts

TextMate recently released an update that changed one of my favorite keyboard shortcuts. This event reminded me that Mac OS X has provided a nice way to create your own keyboard shortcut key bindings. To create your own keyboard shortcut for an application, you will need to know the exact name given in the application’s menu.

Example

Creating new keyboard shortcut for changing tab in TextMate:
1. Found action in app menu to assign keyboard shortcut to

2. Open System Preferences

3. View keyboard shortcuts window

4. Click plus button to add new shortcut

5. Click add and celebrate!

Taking Screenshots In Selenium Using Ruby

I LOVE being able to take screenshots of my Selenium tests as they are running!

Here’s how I take screenshots of my selenium tests running, written in Ruby:

  • Find the variable referencing the selenium driver. Might look something like this:
    @selenium_driver = Selenium::Client::Driver.new(.....
  • Wait for condition to take screenshot. Example:
    page.wait_for_element("//h1", {:timeout_in_seconds => 10})
  • Take screenshot. Example:
    @selenium_driver.capture_entire_page_screenshot(File.expand_path(File.dirname(__FILE__)) + 'screenshot1.png', '')

    or something simpler like:

    @selenium_driver.capture_entire_page_screenshot('~/Desktop/screenshot1.png', '')

Selenium documentation for using the capture screenshot function.

How to get jQuery elements from an array of selectors



To use an array of strings as jQuery selectors I have found the need to append an empty string.
My bad example works because it coerces the ‘this’ object to a string.

Bad Example:

array = ["h1","p","div"];
$K(array).each(function() {
    console.warn( $K(this+"").children() );
});

Much Better Example:

array = ["h1","p","div"];
$K(array).each(function(index, value) {
    console.warn( $K(value).children() );
});

I had previously tried the following with out success

array = ["h1","p","div"];
$K(array).each(function() {
    console.warn( $K(this).children() );
});

The problem of what I was originally trying was that each item in the array wasn’t being treated as a string, I think.The problem of what I was originally trying was that ‘this’ is an object and not a string like I need for the jQuery selector.

A big thanks goes out to my friends,Alex Olson & Sam Curren, for helping me understand my mistake while being tired.

If I didn’t need to do something different for each time through the loop I could do something like this stack overflow answer:

array = ["h1","p","div"];
console.warn( $K( array.join(", ") ).children() );

IE content not scrolling in overflow container

IE content not scrolling bug

IE content not scrolling bug

If you have some content in a container and the content isn’t scrolling, there is probably an easy fix. If any of the content inside the container that is position relative, the container must also be position relative.

Doesn’t work in IE

<div id="scroller" style="overflow-y:scroll">
  <p style="position:relative">Lorem ipsum dolor sit amet, consectetur</p>
  <p style="position:relative">Lorem ipsum dolor sit amet, consectetur</p>
  <p style="position:relative">Lorem ipsum dolor sit amet, consectetur</p>
  <p style="position:relative">Lorem ipsum dolor sit amet, consectetur</p>
  <p style="position:relative">Lorem ipsum dolor sit amet, consectetur</p>
  <p style="position:relative">Lorem ipsum dolor sit amet, consectetur</p>
</div>

Works in IE

<div id="scroller" style="overflow-y:scroll;position:relative">
  <p style="position:relative">Lorem ipsum dolor sit amet, consectetur</p>
  <p style="position:relative">Lorem ipsum dolor sit amet, consectetur</p>
  <p style="position:relative">Lorem ipsum dolor sit amet, consectetur</p>
  <p style="position:relative">Lorem ipsum dolor sit amet, consectetur</p>
  <p style="position:relative">Lorem ipsum dolor sit amet, consectetur</p>
  <p style="position:relative">Lorem ipsum dolor sit amet, consectetur</p>
</div>

Photo by Anderson Mancini