How to deal with a page which fails to load and continue testing in Watir-Webdriver

前端 未结 2 407
温柔的废话
温柔的废话 2021-01-16 12:19

I have looked for answer on other questions but I can\'t find one.

My problem is that I have a number of results that I need to test but my script keeps failing when

相关标签:
2条回答
  • 2021-01-16 12:50

    This question you are asking, and this sort of problem probably points to a much larger problem in how you are organizing and running scripts.

    The first suggestion I would have in most cases would be to use an existing test framework, test/unit cucumber, fitness etc. All of these are designed to run tests as small atomic items which report a failure if anything goes wrong and then move to the next test. (opposed to most homebrewed scripts that are very often a giant long sequence which breaks if something goes amiss and cannot cope with any unexpected failure, or some kind of processing loop stepping through a file, and still have the same kinds of issues. I'm not sure if that would apply to you as you seem to be using watir for scraping more than testing as far as I can tell.

    If you are rolling your own framework, then this is something you need to design into the system. It's called 'exception handling' and the basic format is as described by Zeljko in his answer. A quick google search will find you multiple tutorials on this aspect of the ruby language.

    Your edited code above is closer to this, but is looking pretty repetitive to me. (although since it is currently showing as all flush left it's hard to make sense of. So I edited it to add indentation, ah that's better...) I would consider turning stuff you repeat three times into a method that takes in the URL and spreadsheet location as parameters which would cut way down on the repetition.

    Also you might find it more useful to wrap just a small number of lines of code inside the begin/rescue/end in order to report a more useful message about what failed. That would allow you to report something like "error loading page #{url}" you could even write that out to your spreadsheet.

    I'd recommend a little reading on how errors can 'bubble up' through the system so that failures can be a little more informative.

    0 讨论(0)
  • 2021-01-16 12:52

    I am not sure how would you test a page that did not load, but try something like this:

    begin
      browser.goto "http://www.mycounciltax.org.uk/results?postcode=WC1N1DF&search=Search"
    rescue => e
      puts "rescued #{e}"
    end
    
    0 讨论(0)
提交回复
热议问题