package Utilities; import java.io.BufferedWriter; import java.io.FileWriter; import java.util.Date; import com.rational.test.ft.object.interfaces.DocumentTestObject; import com.rational.test.ft.object.interfaces.GuiTestObject; import com.rational.test.ft.object.interfaces.TextGuiTestObject; import com.rational.test.ft.object.interfaces.TopLevelTestObject; import com.rational.test.ft.vp.ITestDataTable; import resources.Utilities.PerformanceRatHelper; /** * Performance testing for Rational Functional Tester * @author Trish Khoo * */ public class PerformanceRat extends PerformanceRatHelper { /** * perfTest * Measures the amount of time it takes for the browser to finish loading. Use this immediately after * an action that causes the page to begin loading. Writes to a CSV log file. If the file does not exist, * it is created. If the file does exist, the results are appended. * @param currentOperation The operation that is currently being measured for performance */ public static void perfTest(String currentOperation) { try { // Number of attempts to check the readyState so far int numberOfTries = 1; // Number of times to check the readyState before giving up int numberOfAttemptsToFind = 20; // Number of time to wait between tries to find an object double waitTime = 0.5; // Time it took to load the page double loadTime; FileWriter filewriter = new FileWriter("C:\\TestLogFiles\\PerformanceTest.csv", true); BufferedWriter bufferedWriter = new BufferedWriter(filewriter); Date date = new Date(); sleep(waitTime); DocumentTestObject browser = new DocumentTestObject(getDocument()); // Loop until readyState can be found try { // Loop until the page is fully loaded while (!browser.getProperty("readyState").toString().equals("complete") && numberOfTries < numberOfAttemptsToFind) { sleep(waitTime); numberOfTries++; } loadTime = numberOfTries * waitTime; bufferedWriter.write(date.toString() + ", " + currentOperation + ", " + loadTime); bufferedWriter.newLine(); bufferedWriter.close(); } catch(Exception e) { logInfo("Test " + currentOperation + " failed with exception: " + e.toString()); } } catch(java.io.IOException e) { stop(); } } /** * logInfo * Logs information in the log file without measuring performance. * @param information The information to log. */ public static void logInfo(String information) { try { FileWriter filewriter = new FileWriter("C:\\TestLogFiles\\PerformanceTest.csv", true); BufferedWriter bufferedWriter = new BufferedWriter(filewriter); Date date = new Date(); bufferedWriter.write(date.toString() + ", " + information); bufferedWriter.newLine(); bufferedWriter.close(); } catch(java.io.IOException e) { stop(); } } }