O2 API/BT Open Zone
From
this API shows an example using WatiN automation for to login into a particular wireless provider (in this case UK's BTOpenZone
screenshot and video
- open O2's Simple Script Edito and enter the following code
var fileWithLoginDetails = @"C:\O2\_USERDATA\BtOpenZone.xml"; new API_BTOpenZone().login(fileWithLoginDetails) .waitNSeconds(20) .logout() .closeInNSeconds(20); //O2File:API_BTOpenZone.cs
- click execute and the login process will start
- here is a video of the login sequence when using an local secrets file:
- here is a variation of what happens when there is no credentials file provided, the user is asked for a Username & Password and the login fails
code
public class API_BTOpenZone { public WatiN_IE ie; public string defaultWebPage; public API_BTOpenZone() { ie = "".ie(0,450,800,700); defaultWebPage = "http://www.google.co.uk"; } public API_BTOpenZone login() { return login(""); } public API_BTOpenZone login(string fileWithLoginDetails) { ie.open(defaultWebPage); if (ie.title("Google")) "we are already conneted to the internet".info(); else if (ie.title("BT Openzone")) { "detected BT Openzone page".info(); // get the login details ICredential credential = fileWithLoginDetails.credential("BtOpenZone"); if (credential==null) { "no file with credentials provided, or no credential of type BtOpenZone found".debug(); credential = ie.askUserForUsernameAndPassword(); } var BTOpenZone_UserName = credential.username(); var BTOpenZone_Password = credential.password(); // populate fields and submit form if (ie.hasField("username") && ie.hasField("password")) { "detected BT Openzone login Form".info(); "submitting login details".debug(); ie.field("username").value(BTOpenZone_UserName); ie.field("password").value(BTOpenZone_Password); ie.buttons()[0].click(); if (ie.hasField("username")) { "Login failed, Aborting worklow".error(); return this; } ie.open(defaultWebPage); if (ie.title("Google").isFalse()) { "Expected Google page did not load".error(); } } } return this; } public API_BTOpenZone logout() { // logout sequence "logging out".debug(); var logoutPage = "https://www.btopenzone.com:8443/accountLogoff/home"; var logoutConfirmedPage = "https://www.btopenzone.com:8443/accountLogoff/home?confirmed=true"; ie.open(logoutPage); ie.open(logoutConfirmedPage); ie.title().info(); if (ie.hasField("username")) "logout ok".info(); else "logout failed".info(); return this; } public API_BTOpenZone closeInNSeconds(int seconds) { ie.closeInNSeconds(seconds); return this; } public API_BTOpenZone waitNSeconds(int seconds) { ie.waitNSeconds(seconds); return this; } }

