learned/learning/to learn RSS 2.0
# Saturday, December 15, 2012

As you know if you have WinHost $5 or $10 plans, you cannot backup databases from SSMS, you have to do it from the Web Control Panel. After getting tired of doing this manually, I decided to automate this… as I have always been a big fan of automating things. This is how you can do it:

Software Requirements:
Selenium IDE
2. Visual Studio (if you’re going to use C#)
3. Java
Selenium Server
5. Firefox browser

Steps involved:
1. Install Selenium IDE from
here, or open Firefox browser and install from the Add-On page. You should have Firefox installed in your machine.
2. Launch the IDE after installing. This is how the IDE looks:


3. The Selenium IDE starts in recording mode, the red button on the top right corner can be used to start or stop recording.
4. Open a Firefox window, and go to WinHost’s control panel page.
5. Enter your username, password, and follow all the steps that you do for manual database backup. The IDE will record every click event, and you should be able to see the events in the IDE getting added.
6. Once you are done with all the tasks, stop recording.
7. Go to File menu, Export Test Case As and choose C# / NUnit / Remote Control, which will generate a C# class.
8. Create a Console Application or a Service. Console Application works well for me.
9. You need to copy parts of code from the IDE generated class. You can put everything in a method, something like this:

   1:              ISelenium selenium;
   2:              StringBuilder verificationErrors;
   4:              selenium = new DefaultSelenium("localhost", 4444, "*chrome", "https://cp.winhost.com/");
   5:              selenium.Start();
   6:              verificationErrors = new StringBuilder();
   8:              selenium.Open("/login.aspx?ReturnUrl=%2fdefault.aspx");
   9:              selenium.Type("id=ctl00_cphMain_loginCP_UserName", "YourUserId");
  10:              selenium.Type("id=ctl00_cphMain_loginCP_Password", "YourPassword");
  11:              selenium.Click("id=ctl00_cphMain_loginCP_Login");
  12:              selenium.WaitForPageToLoad("30000");
  13:              selenium.Click("id=sites");
  14:              selenium.WaitForPageToLoad("30000");
  15:              selenium.Click("id=ctl00_cphMain_gvSites_ctl02_lbManage");
  16:              selenium.WaitForPageToLoad("30000");
  17:              selenium.Click("css=img[alt=\"Microsoft SQL Manager\"]");
  18:              selenium.WaitForPageToLoad("30000");
  19:              selenium.Click("id=" + labelName);
  20:              selenium.WaitForPageToLoad("30000");
  21:              selenium.Click("link=Backup");
  22:              selenium.WaitForPageToLoad("30000");
  23:              selenium.Click("id=ctl00_cphMain_btnBackup");
  24:              var confirmation = Regex.IsMatch(selenium.GetConfirmation(), "^Create backup\\. Are you sure[\\s\\S]$");
  25:              selenium.WaitForPageToLoad("30000");

10. Install Selenium related DLLs from Nuget. Open Visual Studio’s Package Manager Console, and install packages - Selenium.RC and Selenium.Support
11. Download Selenium Server from
here, you SHOULD have Java installed in your machine to start the server.
12. The server should be started before executing the above code, you can create a .bat file, with this line “java -jar D:\Utils\selenium-server-standalone-2.25.0.jar” in it.
13. You can execute the bat file like this - System.Diagnostics.Process.Start(@"D:\Utils\startSeleniumServer.bat");
14. Now, when you start the console app, it will repeat the recorded steps, and backup your database.
15. Remember, the database will be backed up in the app_data folder; and if the folder already has a backup file, you need to delete it. You could write a FTP module or use the FTP Utility that I wrote (attached) to delete and download the backup file.
16. You have to pass the file path and the credentials if you’re using my FTP utility. The file path will be something like this -

Note: You could use Selenium.WebDriver instead of RC Server, however, it doesn’t handle popup or confirmation window properly; as our process opens a confirmation window, I went with the RC Server.

Download FTP Utility

Saturday, December 15, 2012 5:07:48 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
.NET | Miscellaneous | Solutions
<December 2012>
About the author/Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2020
Sign In
Total Posts: 41
This Year: 0
This Month: 0
This Week: 0
Comments: 47
Pick a theme:
All Content © 2020, Gokulnath
DasBlog theme 'Business' created by Christoph De Baene (delarou)