/* * YahooLogin.java * TSJAPI v1.3.0 * 15 March 2005 * © Quality Forge, 2004-2005 */ /***************************************************************************** YahooLogin.java Sample java 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) *****************************************************************************/ //package <...> import java.util.Hashtable; import qualityforge.testsmith.tsjapi.JSmith; import qualityforge.testsmith.tsjapi.InSessionException; import qualityforge.testsmith.tsjapi.UninitializedException; public class YahooLogin extends JSmith { /** * @param data (no data required) */ public int run(Hashtable 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("Reports\\jYahooLogin"); //to run without generating any TestSmith reports use: //int initialized = initSession(NO_REPORT); if (initialized == FALSE) { //handle error... //use getLastCError() for errors generated by TSAPI //use getLastJError() for errors generated by JSmith return -1; } } catch (InSessionException e) { //handle error, e.g. System.err.println(e.toString()); 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. String ieBrowser = "'C:/Program Files/Internet Explorer/IEXPLORE.EXE'"; int envSet = setEnv("LAUNCH=" + ieBrowser); if (envSet == FALSE) { //handle error... //use getLastCError() for errors generated by TSAPI //use getLastJError() for errors generated by JSmith return -1; } //run test int lasterr = 0; //... //identify the IE browser window //note approximate match on the title String wtitle = "'Microsoft Internet Explorer'"; lasterr = wndInit("id=1 wtitle~=" + wtitle + SPACE + "wclass=IEFrame wrect=MAXIMIZED"); if (lasterr == NO_ERR) { //id and wnum are the same for all calls, so make a constant //note: update the wnum param if the plyback issues multiple warnings. final String window_id = "id=1 wnum={wnum} "; //range and sync params are the same for most calls, so make a constant final String common_params = " hrange=100 zsync=s10 zinterval=s2"; //Navigate to my.yahoo.com lasterr = htmlNavigate(window_id + " url=http://my.yahoo.com/"); //Click sign-in link lasterr = htmlLink(window_id + " htag=A hidx=33 hhref~='login.yahoo.com/config/login','src=my' " + "hvistext='Sign In'" + common_params); //Enter name lasterr = htmlText(window_id + " htag=INPUT hidx=84 htype=text hname=login " + "hvalue=smith030615" + common_params); //Enter (obfuscated) password lasterr = htmlText(window_id + " htag=INPUT hidx=89 htype=password " + "hvalue=[!OBF!]/!*%2B&!#.%2B!#" + common_params); //click Submit button lasterr = htmlInput(window_id + " htag=INPUT hidx=93 htype=submit " + "hvalue='Sign In'" + common_params); //Validate the greeting/user name. lasterr = valHtmlText(window_id + " htag=P hidx=30 hoffset=0 " + " remark='Validate the greeting [Welcome, smith030615].'" + " hvistext='Welcome%cm smith030615'" + common_params); //This validation is intended to fail String unknown = "non-existent text !@#$%^&*"; lasterr = valHtmlText(window_id + " htag=B hidx=33 hoffset=0 " + " remark='validation for \"" + unknown + "\" is intended to fail.'" + " remark2='validation for \"" + unknown + "\" will have failed.'" + " hvistext='" + unknown + "' zsync=s5"); //check for error (this can be done after any - or every - command) if (lasterr > NO_ERR) { //handle error } //Click the Sign Out link lasterr = htmlLink(window_id + " htag=A hidx=33 " + "hhref~='http://login.yahoo.com','logout=1' " + "hvistext='Sign Out'" + common_params); //Validate that sign out was successful. (1 of 2 possible strings) lasterr = valHtmlText(window_id + " htag=B hidx=49 hoffset=0 " + "hvistext='You have signed out of the Yahoo! network' " + common_params); //Close the IE Browser lasterr = wndClose("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. System.err.println(e.toString()); return -1; } } //============================================================================= //TEST public static void main(String[] args) { YahooLogin yahooLogin = new YahooLogin(); int exitCode = yahooLogin.run(); System.out.println("exitCode: " + exitCode); //show the TestSmith report in a browser window JSmith.displayLastReport(); } //============================================================================= }