Skip to content

Commit

Permalink
Make window recording work with powershell
Browse files Browse the repository at this point in the history
  • Loading branch information
kapoorlakshya committed Jul 30, 2024
1 parent fa77d0d commit 61d0bdd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
6 changes: 3 additions & 3 deletions lib/screen-recorder/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ def execute_command(cmd, log = options.log)
#
def new_process(process)
if OS.windows?
ChildProcess.new('cmd.exe', '/c', process)
ChildProcess.new('powershell.exe', '/c', process)
else
ChildProcess.new('sh', '-c', process)
ChildProcess.new(process)
end
end
end
end
end
6 changes: 3 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 @@ -39,8 +39,8 @@ def window_title_for(process_name)
raise NotImplementedError, 'Only Microsoft Windows (gdigrab) supports window capture.' unless OS.windows?

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
# output = output.encode('iso-8859-1').force_encoding('utf-8') unless output.valid_encoding?
titles = output
.split("\n")
.map { |i| i.gsub(FILTERED_TITLES, '') }
.reject(&:empty?)
Expand Down
7 changes: 4 additions & 3 deletions spec/screen-recorder/window_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
end

before do
browser.goto 'watir.com'
browser.goto 'google.com'
browser.wait
browser.window.maximize
end

after { browser.close }
Expand All @@ -27,10 +28,10 @@
recorder.stop

aggregate_failures do
expect(recorder.options.all[:input]).to include('Watir Project')
expect(recorder.options.all[:input]).to include('Google')
expect(File).to exist(recorder.options.output)
expect(recorder.video.valid?).to be(true)
end
end
end
end
end

0 comments on commit 61d0bdd

Please sign in to comment.