/* * YahooLogin.cpp * TSCAPI v1.3.0 * 15 March 2005 * © Quality Forge, 2004-2005 */ /***************************************************************************** YahooLogin.cpp Sample C++ test-script demonstrating web page login. This script will login the user 'smith030615' to My Yahoo!, validate some text on the login page, attempt to validate some nonexistent text to show an error message example, logout the user and validate text on the logout page. ---------------------------------------------------------------------------- Description of the System on which the script was recorded: Windows 2000, Screen Size: 1024 x 768, Color: High Color (16 bit) *****************************************************************************/ #include "YahooLogin.h" /** * $param data: no data required */ int YahooLogin::Run(LPTSTR data) { //initialize try { //initialize test //note: the \Reports directory must already exist in the // same directory where this java class file exists int initialized = InitSession((LPTSTR)"reports\\cYahooLogin"); //to run without generating any TestSmith reports use: //int initialized = initSession(); if (initialized == FALSE) { //handle error... //use getLastTSError() for errors generated by TSAPI //use getLastCError() for errors generated by CSmith return -1; } } catch (InSessionException e) { //handle error, e.g. printf((LPTSTR)"[%s]\n", e.reason); return -1; } try { //set environment //... //Launch an IE Browser //IEXPLORE.EXE is assumed to reside in "C:\Program Files\Internet Explorer" //Change the path as appropriate for your own system. int envSet = SetEnv((LPTSTR)"LAUNCH='C:/Program Files/Internet Explorer/IEXPLORE.EXE'"); if (envSet == FALSE) { //handle error... //use getLastTSError() for errors generated by TSAPI //use getLastCError() for errors generated by CSmith printf((LPTSTR)"[%s]\n", GetLastTSError()); return -1; } //run test int lasterr = 0; //... //write a remark to the report Noop((LPTSTR)"remark='C++ Yahoo Login Test'"); //identify the IE browser window //note approximate match on the title lasterr = WndInit((LPTSTR)"id=1 wtitle~='Microsoft Internet Explorer' " "wclass=IEFrame wrect=MAXIMIZED"); if (lasterr == NO_ERR) { LPTSTR params; params = (LPTSTR)malloc(256); //id and wnum are the same for all calls, so make a constant //note: update the wnum param if the playback issues multiple warnings. LPCTSTR window_id = "id=1 wnum={wnum} "; //range and sync params are the same for most calls, so make a constant LPCTSTR common_params = " hrange=100 zsync=s10 zinterval=s2"; //Navigate to my.yahoo.com sprintf(params, "%s %s", window_id, (LPTSTR)"url=http://my.yahoo.com/"); lasterr = HtmlNavigate(params); //Click sign-in link sprintf(params, "%s %s %s", window_id, (LPTSTR)" htag=A hidx=33 hhref~='login.yahoo.com/config/login','src=my' hvistext='Sign In'", common_params); lasterr = HtmlLink(params); //Enter name sprintf(params, "%s %s %s", window_id, (LPTSTR)"htag=INPUT hidx=84 htype=text hname=login hvalue=smith030615 ", common_params); lasterr = HtmlText(params); //Enter (obfuscated) password sprintf(params, "%s %s %s", window_id, (LPTSTR)"htag=INPUT hidx=89 htype=password hvalue=[!OBF!]/!*%2B&!#.%2B!# ", common_params); lasterr = HtmlText(params); //click Submit button sprintf(params, "%s %s %s", window_id, (LPTSTR)"htag=INPUT hidx=93 htype=submit hvalue='Sign in' ", common_params); lasterr = HtmlInput(params); //Validate the greeting/user name. sprintf(params, "%s %s %s", window_id, (LPTSTR)"htag=P hidx=30 hoffset=0 remark='Validate the greeting [Welcome, smith030615].' hvistext='Welcome%cm smith030615'", common_params); lasterr = ValHtmlText(params); //This validation is intended to fail sprintf(params, "%s %s %s %s %s", window_id, (LPTSTR)"htag=B hidx=33 hoffset=0", (LPTSTR)"remark='validation for [non-existent text !@#$%^&*] is intended to fail.'", (LPTSTR)"remark2='validation for [non-existent text !@#$%^&*] will have failed.'", (LPTSTR)"hvistext='[non-existent text !@#$%^&*]' zsync=s5"); lasterr = ValHtmlText(params); //check for error (this can be done after any - or every - command) if (lasterr > NO_ERR) { //handle error } //Click the Sign Out link sprintf(params, "%s %s %s", window_id, (LPTSTR)"htag=A hidx=33 hhref~='http://login.yahoo.com','logout=1' hvistext='Sign Out'", common_params); lasterr = HtmlLink(params); //Validate that sign out was successful. (1 of 2 possible strings) sprintf(params, "%s %s %s", window_id, (LPTSTR)"htag=B hidx=49 hoffset=0 hvistext='You have signed out of the Yahoo! network'", common_params); lasterr = ValHtmlText(params); //Close the IE Browser lasterr = WndClose((LPTSTR)"id=1"); } //end test int exit_ok = ExitSession(); if (exit_ok == 0) { //handle error... //use getLastCError() for errors generated by TSAPI //use getLastJError() for errors generated by JSmith } //full test ran without exceptions, so return GetExitCode(); } catch (UninitializedException e) { //handle error, e.g. printf((LPTSTR)"[%s]\n", e.reason); return -1; } } //============================================================================= //TEST int main(int argc, char* argv[]) { YahooLogin* yahooLogin = new YahooLogin(); int exitCode = yahooLogin->Run(); printf("exitCode: %d\n\n", exitCode); CSmith::DisplayLastReport(); delete yahooLogin; return exitCode; } //=============================================================================