Re: [Wtr-general] Subject:,Re: launch broswer as another user ?

2006-08-23 Thread David Schmidt
We've also had a need to start up multiple instances of IE, each in 
their own process.  (This allows us to run multiple scraping sessions to 
the same site and not have the session cookies over-ride each other, as 
long as the cookies don't have an expiration date which writes them to 
the file system.)

Try this function in your app to start up each IE in it's own process:

  # This function starts each window as a unique IE process.
  # This allows the session cookies set for each IE scrape and
  # not overwrite session cookies set in other scraper sessions.
  def start_ie
tf = Tempfile.new("scraper")
basename = tf.path.sub(/^.*[\/\\]([^\/\\]*$)/, '\1')  # get base 
filename
html = sprintf("%s", basename)
tf.puts(html)
tf.close
system("start iexplore #{tf.path}")
ie = nil
Watir::until_with_timeout(5) do
  begin
ie = Watir::IE.attach(:url, /#{basename}/)
  rescue Watir::Exception::NoMatchingWindowFoundException
false
  end
end
return ie
  end

This does bring up a problem that we've had, however.

If you try to start each IE as a different user then this method doesn't 
work, and click_no_wait doesn't work either.  Apparently a process 
spawned from that IE running as a different user doesn't have the same 
permissions as a process running under as the logged in user.  The call 
to find a window using Windows "Shell.Application" cannot see *any* IE 
windows if the spawning process is running as a different user.  In 
addition, the logged in user cannot see any IE window created by another 
user.

We haven't come up with a solution for this problem as it appears to be 
a problem in User32.dll used by Shell.Application.

David

Bret Pettichord wrote:
> Lonny Eachus wrote:
>   
>> Wow. Seems like an awful lot of work. Why not just use shell to start 
>> IE as any user you want using the Windows "RunAs" command, then attach 
>> to the window?
>> Two short lines of code.
>> 
> In my case i needed to start up several browsers concurrently and in 
> this scenario, the only way to attach to them reliably and cleanly is to 
> know the process id of each browser. I stole most of the code from Alex 
> Verk, so it wasn't really a lot of coding on my part.
>
> If you know of an easier way ("Two short lines of code") to help Marco, 
> i'm sure he and others would appreciate seeing it.
>
> Bret
>
> ___
> Wtr-general mailing list
> Wtr-general@rubyforge.org
> http://rubyforge.org/mailman/listinfo/wtr-general
>   

___
Wtr-general mailing list
Wtr-general@rubyforge.org
http://rubyforge.org/mailman/listinfo/wtr-general


Re: [Wtr-general] Subject:,Re: launch broswer as another user ?

2006-08-21 Thread Bret Pettichord
Lonny Eachus wrote:
> Wow. Seems like an awful lot of work. Why not just use shell to start 
> IE as any user you want using the Windows "RunAs" command, then attach 
> to the window?
> Two short lines of code.
In my case i needed to start up several browsers concurrently and in 
this scenario, the only way to attach to them reliably and cleanly is to 
know the process id of each browser. I stole most of the code from Alex 
Verk, so it wasn't really a lot of coding on my part.

If you know of an easier way ("Two short lines of code") to help Marco, 
i'm sure he and others would appreciate seeing it.

Bret

___
Wtr-general mailing list
Wtr-general@rubyforge.org
http://rubyforge.org/mailman/listinfo/wtr-general


[Wtr-general] Subject:,Re: launch broswer as another user ?

2006-08-21 Thread Lonny Eachus




Wow. Seems like an awful lot of work. Why not just use shell to start
IE as any user you want using the Windows "RunAs" command, then attach
to the window?
Two short lines of code.

Lonny Eachus
==


  

  

Subject:

Re: [Wtr-general] launch broswer as another user ?
  
  

From: 
Bret Pettichord <[EMAIL PROTECTED]>
  
  

Date: 
Mon, 21 Aug 2006 14:55:10 -0500
  

  
  
Marco wrote:
  
  Hi


has anyone had to come up with a way of launching an instance of ie
from within a script but run as another user context?


I tried using cpau and I can launch a browser using a ruby script. I
then run that script using 
cpau -u  -p  -ex "cmd /K \"launchbrowser.rb
"" -enc -file launchbrowser.job


cpau -dec -file launchbrowser.job


whilst this works fine to run the script standalone when I try to run
this script from within a testcase using


puts("Foo1")

exec "cpau -dec -file launchbrowser.job"

puts("Foo2")


the browser launches but the testcase dosen't run through to
completition drops out to cmd prompt as soon as the exec finishes.


the plan was then to use ie.attach to attach to this browser window


I'm hoping someone else has an easier / better idea to do this sort of
thing?

  
The code below should be a step in the right direction. I have been
using this and expect contribute it to the main watir code base at some
point.
  
  
Bret
  
  
  
# based on http://svn.instiki.org/instiki/trunk/test/watir/e2e.rb
  
# and
http://rubyforge.org/pipermail/wtr-general/2005-November/004108.html
  
  
require 'watir'
  
  
class IEProcess
  
 def self.start
  
   startup_info = [68].pack('lx64')
  
   process_info = [0, 0, 0, 0].pack('')
  
      # TODO: make this portable
  
   startup_command = 'C:\Program Files\Internet Explorer\IEXPLORE.EXE'
  
      result = Win32API.new('kernel32.dll', 'CreateProcess',
'pplppp', 'l').
  
 call(
  
  nil,
  
  startup_command,
  
  0, 0, 1, 0, 0, '.', startup_info, process_info)
  
      # TODO print the error code, or better yet a text message
  
   raise "Failed to start IEXPLORE." if result == 0
  
      process_id = process_info.unpack('')[2]
  
   puts "Process ID: #{process_id}"
  
   self.new process_id
  
 end
  






___
Wtr-general mailing list
Wtr-general@rubyforge.org
http://rubyforge.org/mailman/listinfo/wtr-general