Skip to content

Commit

Permalink
Fix titles spec
Browse files Browse the repository at this point in the history
  • Loading branch information
kapoorlakshya committed Jul 21, 2024
1 parent ee3b1d9 commit fa77d0d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
8 changes: 5 additions & 3 deletions lib/screen-recorder/window.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Window < Common
def initialize(title:, output:, advanced: {})
raise 'Window recording is only supported on Microsoft Windows.' unless OS.windows?

super(input: %("title=#{title}"), output: output, advanced: advanced)
super(input: "title=#{title}", output: output, advanced: advanced)
end

class << self
Expand Down Expand Up @@ -38,7 +38,9 @@ def fetch_title(process_name)
def window_title_for(process_name)
raise NotImplementedError, 'Only Microsoft Windows (gdigrab) supports window capture.' unless OS.windows?

titles = `tasklist /v /fi "imagename eq #{process_name}.exe" /fo list | findstr Window`
output = `tasklist /v /fi "imagename eq #{process_name}.exe" /fo list | findstr Window`
encode = output.encode('iso-8859-1').force_encoding('utf-8')
titles = encode
.split("\n")
.map { |i| i.gsub(FILTERED_TITLES, '') }
.reject(&:empty?)
Expand All @@ -58,4 +60,4 @@ def warn_on_mismatch(titles, process_name)
end
end
end
end
end
22 changes: 11 additions & 11 deletions spec/screen-recorder/titles_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
end
end

context 'when the given application is Firefox', if: ScreenRecorder::OS.windows? do
let(:browser_process) { :firefox }
context 'when the given application is a browser', if: ScreenRecorder::OS.windows? do
let(:browser_process) { :chrome }
let(:url) { 'https://google.com' }
let(:expected_title) { /Google [-—] Mozilla Firefox/ }
let(:expected_title) { /Google - Google Chrome for Testing/ }
let(:browser) do
Watir::Browser.new browser_process
Watir::Browser.new browser_process, options: { args: ['--disable-gpu'] }
end

before do
Expand All @@ -27,31 +27,31 @@

it 'returns a list of available windows from firefox' do
browser.wait
expect(described_class.fetch('firefox')).to be_a(Array)
expect(described_class.fetch('chrome')).to be_a(Array)
end

it 'does not return an empty list' do
browser.wait
expect(described_class.fetch('firefox').empty?).to be(false)
end

it 'returns window title from Mozilla Firefox' do
it 'returns window title from browser' do
expect(described_class.fetch(browser_process).first).to match(expected_title)
end
end

context 'when a firefox window is not open', if: ScreenRecorder::OS.windows? do
context 'when a browser window is not open', if: ScreenRecorder::OS.windows? do
it 'raises an exception' do
expect { described_class.fetch('firefox') }.to raise_exception(ScreenRecorder::Errors::ApplicationNotFound)
expect { described_class.fetch('chrome') }.to raise_exception(ScreenRecorder::Errors::ApplicationNotFound)
end
end

context 'when application is Chrome with extensions as individual processes', if: ScreenRecorder::OS.windows? do
let(:browser_process) { :chrome }
let(:url) { 'https://google.com' }
let(:expected_titles) { ['Google - Google Chrome'] }
let(:expected_titles) { ['Google - Google Chrome for Testing'] }
let(:browser) do
Watir::Browser.new browser_process
Watir::Browser.new browser_process, options: { args: ['--disable-gpu'] }
end

before do
Expand All @@ -67,4 +67,4 @@
expect(described_class.fetch(browser_process)).to eql(expected_titles)
end
end
end
end

0 comments on commit fa77d0d

Please sign in to comment.