Csh
Csh

Reputation: 103

Re-run script upon obtaining error on a webpage

I am using Selenium WebDriver to automate the downloading of videos from a few online video converting sites.

Basically, all the user has to do is enter the URL of a YouTube video and the program will run the script to download the videos for you.

Everything runs very smoothly, but the problem is when the website fails to convert the video.

For example, clipconverter.cc sometimes throws an "Unable to get video infos from YouTube" error, but it works when you try again. I have done some error checking in the event that there are missing elements and the program will stop running the script but in the example I mentioned above, I want to re-run the script again.

What is a possible way of achieving this? Do I have to re-create the error page and get the elements presented there?

Upvotes: 1

Views: 91

Answers (1)

ekostadinov
ekostadinov

Reputation: 6940

Since you are not using Selenium as your test engine, but as a web scraper - IMHO it's actually a matter of your workflow to handle such states. This could be a corner case of a Defensive programming, but still can design it to handle such scenarios when/if they happen.

What is a possible way of achieving this? Do I have to re-create the error page and get the elements presented there?

Once you detect such error message (via the Selenium's functionality)

when the website fails to convert the video

you can call the same piece of code that handled the first request, but this time just pass the parameters you already have (videoURL, user etc.). In case you re-try and this site still fails, you can ask another one to carry out the download (as a failover scenario).

For the design I would use a mixture of

  • Command to take care of the user requests/responses
  • Observer to notify me for the changes
  • State for altering the behavior when the downloading process internal state changes

Upvotes: 1

Related Questions