diff --git a/lib/screen-recorder/window.rb b/lib/screen-recorder/window.rb index f6cfb4e..2c4e452 100644 --- a/lib/screen-recorder/window.rb +++ b/lib/screen-recorder/window.rb @@ -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 @@ -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?) @@ -58,4 +60,4 @@ def warn_on_mismatch(titles, process_name) end end end -end \ No newline at end of file +end diff --git a/spec/screen-recorder/titles_spec.rb b/spec/screen-recorder/titles_spec.rb index 0cadc2f..a92e0c6 100644 --- a/spec/screen-recorder/titles_spec.rb +++ b/spec/screen-recorder/titles_spec.rb @@ -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 @@ -27,7 +27,7 @@ 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 @@ -35,23 +35,23 @@ 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 @@ -67,4 +67,4 @@ expect(described_class.fetch(browser_process)).to eql(expected_titles) end end -end \ No newline at end of file +end