Security Alerts

Security Alerts

If the site you are testing uses https, but the certificate is not correct, you may see this dialog. An incorrect certificate can occur if you create and install your own certificates, or a real certificate has an expired date, or if there is some redirection happening behind the scenes.

Again, this is really difficult to do a working demo for.

How do I access a security alert window?

Here is an example of clicking 'yes' on a security window when accessing a site:

class Browser
  def initialize
    $ie = Watir::IE.new
  end

  def goto(url)
    @url = url
    t = Thread.new(){
    puts "winclicker thread started"
    wc = WinClicker.new
    wc.clearSecurityAlertBox
    }
    m = Thread.new($ie) {
    $ie.goto(@url)
    }
    m.join
    t.join

    $ie.bring_to_front
    $ie.maximize
  end
end

browser = Browser.new
browser.goto('https://server_name/')

Autoclick yes when a security alert window pops up?

Whenever a security alert or security information popup occurs when navigating to a site, yes will be auto clicked.
Two methods need to be changed in C:\ruby\lib\ruby\gems\1.8\gems\watir-1.6.2\lib\watir\ie-class.rb file.
Replace goto, wait with the below code. Goto is modified for IE7, IE8 navigation when there is a certificate error.
Note: The below code works only when using watir 1.6.2. No extra code need to be used in the testcase to handle these popups in IE6.

# Navigate to the specified URL.
    #  * url - string - the URL to navigate to
    def goto(url)
      @ie.navigate(url)
      wait
      if self.title == "Certificate Error: Navigation Blocked"
        #handle security error in IE 7, IE 8 shows up as a webpage and not dialog
        self.link(:id, "overridelink").click
      end
      return @down_load_time
    end

    # Block execution until the page has loaded.
    # =nodoc
    # Note: This code needs to be prepared for the ie object to be closed at
    # any moment!
    def wait(no_sleep=false)
      @rexmlDomobject = nil
      @down_load_time = 0.0
      a_moment = 0.2 # seconds
      start_load_time = Time.now
      outval = ' ' * 30
      popwndtitle = ''
      begin
        while @ie.busy # XXX need to add time out
          sleep a_moment
          # 1-SECURITY INFORMATION - PAGE CONTAINS BOTH SECURE AND INSECURE ITEMS YES-6
          # 2-Security Alert - Certificate error YES-1
          pophwnd = Win32API.new("user32", "GetWindow", 'Li', 'L').Call(@ie.hwnd.to_i, 6)
          # only handle if there is a popup and handle only 2 popups, if any other popups occur return.
          if pophwnd !=0
            Win32API.new("user32", "GetWindowText", 'Lpi', 'L').Call(pophwnd,outval,30)
            popwndtitle = outval.rstrip.chomp("\000")
            return 0 if !(popwndtitle.include?("Security Alert") || popwndtitle.include?("Security Information"))
            cntrlhwndYES = Win32API.new("user32", "GetDlgItem", 'Li', 'L').Call(pophwnd, 1)
            Win32API.new("user32", "SendMessage",'LLLL','L').Call(cntrlhwndYES, 0x0006, 1,0)
            Win32API.new("user32", "SendMessage",'LLLL','L').Call(cntrlhwndYES, 0x00F5, 0,0)
            cntrlhwndYES = Win32API.new("user32", "GetDlgItem", 'Li', 'L').Call(pophwnd, 6)
            Win32API.new("user32", "SendMessage",'LLLL','L').Call(cntrlhwndYES, 0x0006, 1,0)
            Win32API.new("user32", "SendMessage",'LLLL','L').Call(cntrlhwndYES, 0x00F5, 0,0)
          end
        end
        until @ie.readyState == READYSTATE_COMPLETE do
          sleep a_moment
        end
        sleep a_moment
        until @ie.document do
          sleep a_moment
        end

        documents_to_wait_for = [@ie.document]

      rescue WIN32OLERuntimeError # IE window must have been closed
        @down_load_time = Time.now - start_load_time
        sleep @pause_after_wait unless no_sleep
        return @down_load_time
      end

      while doc = documents_to_wait_for.shift
        begin
          until doc.readyState == "complete" do
            sleep a_moment
          end
          @url_list << doc.location.href unless @url_list.include?(doc.location.href)
          doc.frames.length.times do |n|
            begin
              documents_to_wait_for << doc.frames[n.to_s].document
            rescue WIN32OLERuntimeError, NoMethodError
            end
          end
        rescue WIN32OLERuntimeError
        end
      end

      @down_load_time = Time.now - start_load_time
      run_error_checks
      sleep @pause_after_wait unless no_sleep
      @down_load_time
    end
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Jul 21, 2009

    Dheeraj says:

    Its working perfectly now Regards D G

    Its working perfectly now

    Regards

    D G