How to enter password in a popup using watir?

前端 未结 3 608
粉色の甜心
粉色の甜心 2021-02-06 14:46

I\'m writing some watir test cases:

browser.goto \"http://egauge2592.egaug.es/\"
browser.link(:href,\"/settings.html\").click
browser.text_field(:index,4).set(\"         


        
3条回答
  •  有刺的猬
    2021-02-06 15:38

    I wrote a firefox plugin to deal with this problem recently. I haven't tried it with headless Firefox, but it might work... worth a try. See the following for details:

    http://www.natontesting.com/2012/10/06/firefox-plugin-test-automation-password-manager/

    To get it working with watir, try the following:

    browser = Watir::Browser.new
    #go to a page that won't bring up the authentication dialog...
    browser.goto 'http://www.google.co.uk'
    
    #prepare the script...
    pass_man_update_script = <<-SCRIPT
    var addCredentialsEvent = new CustomEvent("add_credentials_to_passman", {
      detail: {
        host: 'http://secure.example.com',
        username: 'bob',
        password: 'P45sword'
      }
    });
    window.dispatchEvent(addCredentialsEvent);
    SCRIPT
    
    #inject the script into the browser:
    browser.execute_script pass_man_update_script
    
    #go to the page that prompts the dialog box...
    browser.goto "http://secure.example.com"
    #you should now be past the dialog box!
    

提交回复
热议问题