When(/^I (?:un)?pause the track$/) do
  on(AudioPlayer::PlayerPage).playpause_button_element.wait_until(&:present?)
  on(AudioPlayer::PlayerPage).playpause_button
end

When(/^I go to the next track$/) do
  on(AudioPlayer::PlayerPage).next_button
end

When(/^I go to the previous track$/) do
  on(AudioPlayer::PlayerPage).previous_button
end

Then(/^the track should be playing$/) do
  on(AudioPlayer::PlayerPage) do |page|
    expect(page.audio).to_not be_paused
    page.wait_until { page.audio.currenttime > 0.5 }
  end
end

Then(/^the track should be paused$/) do
  @browser.alert.ok if @browser.alert.exists?
  expect(on(AudioPlayer::PlayerPage).audio).to be_paused
end

Then(/^the track should be (Track \d+)$/) do |tn|
  expect(on(AudioPlayer::PlayerPage).track_info_element.text).to eq(tn)
end
