|
Example Program #04
This is what a sample C++ program that illustrates retrieval of the
complete eValid EventLog during the EPI program playback.
During the playback there are several in-the-browser AJAX-type synchronization steps. Also, the script performs and IndexFindElement command that is paralleled in the program. Finally, there is a SaveRecord command to record the results to a local file.
The eValid script sequence that corresponds to this program is shown below.
#include "stdafx.h" #include "epi.h" using namespace std; void TraceEvalidLog(IEvalid * p) { if (p == NULL) return; IEvalidLogCollection * pColl; if (SUCCEEDED(p->get_LastPlaybackLog(&pColl))) { long numItems; pColl->get_length(&numItems); for(long i = 0; i < numItems; ++i) { IEvalidLog * pLog; pColl->item(i, &pLog); long seq, cmd, line, a, f, t; CComBSTR date, time, prj, grp, tst, stat, msg; pLog->get_accumTime(&a); pLog->get_cmdNum(&cmd); pLog->get_date(&date); pLog->get_fineTime(&f); pLog->get_groupName(&grp); pLog->get_lineNum(&line); pLog->get_message(&msg); pLog->get_projectName(&prj); pLog->get_seqNum(&seq); pLog->get_status(&stat); pLog->get_testName(&tst); pLog->get_time(&time); pLog->get_totalCmdTime(&t); pLog->Release(); cout << CString(date) << " " << CString(time) << "\t" << seq << "\t" << cmd << "\t" << line << "\t" << CString(prj) << "\t" << CString(grp) << "\t" << CString(tst) << "\t" << CString(stat) << "\t" << a << "\t" << f << "\t" << t << "\t" << CString(msg) << endl; } pColl->Release(); } } int main() { ::CoInitialize(NULL); IEvalid * pEvalid = NULL; HRESULT hr = CoCreateInstance(CLSID_Evalid, NULL, CLSCTX_INPROC_SERVER, IID_IEvalid, (void**)&pEvalid); if (SUCCEEDED(hr)) { // ---------------------------------------------------------------------------- pEvalid->InitLink(CComBSTR("http://www.google.com")); TraceEvalidLog(pEvalid); pEvalid->Wait(3959); TraceEvalidLog(pEvalid); pEvalid->InputValue(0, 167, CComBSTR("TEXT"), CComBSTR(""), CComBSTR("q"), CComBSTR("batteries"), CComBSTR(""), CComBSTR("")); TraceEvalidLog(pEvalid); pEvalid->Wait(3264); TraceEvalidLog(pEvalid); pEvalid->SubmitClick(0, 213, CComBSTR(""), CComBSTR("btnG"), CComBSTR("Google Search"), CComBSTR("")); TraceEvalidLog(pEvalid); pEvalid->Wait(2734); TraceEvalidLog(pEvalid); pEvalid->IndexSet(0); TraceEvalidLog(pEvalid); pEvalid->IndexFindElement(0, CComBSTR("DOWN"), CComBSTR("innerText"), CComBSTR("Next"), NULL, NULL); TraceEvalidLog(pEvalid); pEvalid->IndexMove(+1); TraceEvalidLog(pEvalid); pEvalid->IndexFollowLink(0, CComBSTR("")); TraceEvalidLog(pEvalid); //pEvalid->IndexFollowLink( 0, CComBSTR( _T( "" ) ), VARIANT_BOOL("VARIANT_FALSE") ); //TraceEvalidLog(pEvalid); pEvalid->Wait(1722); TraceEvalidLog(pEvalid); pEvalid->ResetTimer(); TraceEvalidLog(pEvalid); pEvalid->GotoLink(0, CComBSTR("http://www.ritzcamera.com/"), CComBSTR("")); TraceEvalidLog(pEvalid); pEvalid->Wait(3904); TraceEvalidLog(pEvalid); pEvalid->InputValue(0, 360, CComBSTR("TEXT"), CComBSTR("searchInput"), CComBSTR("keyword"), CComBSTR("batteries"), CComBSTR(""), CComBSTR("")); TraceEvalidLog(pEvalid); pEvalid->Wait(2440); TraceEvalidLog(pEvalid); pEvalid->InputImageClick(0, 363, CComBSTR("http://a1672.g.akamai.net/7/1672/116/$_Year$_Month201/" \ "www.ritzcamera.com/graphics/navigation/09/search09.gif"), CComBSTR(""), CComBSTR(""), true); TraceEvalidLog(pEvalid); pEvalid->ElapsedTime(CComBSTR("Going to Ritz")); TraceEvalidLog(pEvalid); pEvalid->GotoLink(0, CComBSTR("http://www.google.com/"), CComBSTR("")); TraceEvalidLog(pEvalid); pEvalid->SyncOnSelectedObjProperty(0, 166, CComBSTR("name"), CComBSTR("btnG"), CComBSTR("tagName"), CComBSTR("INPUT"), CComBSTR("")); TraceEvalidLog(pEvalid); long index; pEvalid->IndexSet(0); TraceEvalidLog(pEvalid); pEvalid->IndexFindElement(0, CComBSTR("DOWN"), CComBSTR("name"), CComBSTR("q"), CComBSTR(""), &index); TraceEvalidLog(pEvalid); pEvalid->IndexInputValue(0, CComBSTR("TEXT"), CComBSTR("apple"), CComBSTR(""), CComBSTR("")); TraceEvalidLog(pEvalid); pEvalid->IndexFindElement(0, CComBSTR("DOWN"), CComBSTR("name"), CComBSTR("btnG"), CComBSTR(""), &index); TraceEvalidLog(pEvalid); pEvalid->IndexFollowLink(0, CComBSTR("")); TraceEvalidLog(pEvalid); pEvalid->ValidateSelectedText(0, 188, 0, CComBSTR("Apple Inc."), CComBSTR("")); TraceEvalidLog(pEvalid); pEvalid->Wait(1552); TraceEvalidLog(pEvalid); pEvalid->ValidateSelectedObjProperty(0, 188, CComBSTR("readyState"), CComBSTR("complete"), CComBSTR("tagName"), CComBSTR("A"), CComBSTR("")); TraceEvalidLog(pEvalid); pEvalid->GotoLinkSubmit(0, CComBSTR("http://search.yahoo.com/search?" \ "p=camera&fr=yfp-t-501&toggle=1&cop=mss&ei=UTF-8"), CComBSTR("")); TraceEvalidLog(pEvalid); pEvalid->SyncOnElementProperty(0, CComBSTR("id"), CComBSTR("yschsp"), CComBSTR("")); TraceEvalidLog(pEvalid); pEvalid->SaveRecord(CComBSTR("tally.txt"), CComBSTR("%E\t%e\t%K\t%T\t%Z\tRitzCamera check for batteries"), true); TraceEvalidLog(pEvalid); pEvalid->ExitNow(); // ---------------------------------------------------------------------------- pEvalid->Release(); } else if (hr == E_ACCESSDENIED) cout << "Missing a valid EPI license key!" << endl; else cout << "Unable to load EPI!" << endl; ::CoUninitialize(); return 0; } |
Resources
Corresponding eValid Script
Here is the corresponding eValid recorded script:
# Start of eValid Script: example04.evs TestID "example04" InitLink "http://www.google.com/" Wait 3959 InputValue 0 167 "TEXT" "" "q" "batteries" "" "" Wait 3264 SubmitClick 0 213 "" "btnG" "Google Search" "" Wait 2734 IndexSet 0 IndexFindElement 0 DOWN "innerText" "Next" "" IndexMove +1 IndexFollowLink 0 "" Wait 1722 ResetTimer GotoLink 0 "http://www.ritzcamera.com/" "" Wait 3904 InputValue 0 360 "TEXT" "searchInput" "keyword" "batteries" "" "" Wait 140 InputImageClick 0 363 "http://a1672.g.akamai.net/7/1672/116/20110901/" \ "www.ritzcamera.com/graphics/navigation/09/" \ "search09.gif" "" "" NAV ElapsedTime "Going to Ritz" GotoLink 0 "http://www.google.com/" "" SyncOnSelectedObjProperty 0 166 "name" "q" "tagName" "INPUT" "" IndexSet 0 IndexFindElement 0 DOWN "name" "q" "" IndexInputValue 0 "TEXT" "apple" "" "" IndexSet 0 IndexFindElement 0 DOWN "name" "btnG" "" IndexFollowLink 0 "" ValidateSelectedText 0 188 0 "Apple Inc." "" Wait 1552 ValidateSelectedObjProperty 0 188 "readyState" "complete" "tagName" "A" "" GotoLinkSubmit 0 "http://search.yahoo.com/search?" \ "p=camera&fr=yfp-t-501&toggle=1&cop=mss&ei=UTF-8" "" SyncOnElementProperty 0 "id" "yschsp" "" SaveRecord "tally.txt" "%E\t%e\t%K\t%T\t%Z\tRitzCamera " \ "check for batteries" OVERWRITE # End of eValid script. |