You can edit the base state in a script to specify how Silk4J starts an application under test (AUT) during replay. You can specify the executable location of the AUT, the working directory, the URL and the connection string for a web application, and so on. For example, if you want to execute tests on a production web site, which have already been executed on a staging web site, you can simply change the URL in the base state and the tests are executed against the new web site.
To edit the base state in a script:
// Go to web page 'demo.borland.com/InsuranceWebExtJS' BrowserBaseState baseState = new BrowserBaseState(); // <-- Insert your changes here! baseState.execute();
baseState.setExecutable(executable);For example, to specify the Calculator, type the following:
baseState.setExecutable("C:\\Windows\\SysWOW64\\calc.exe");To specify Mozilla Firefox, type the following:
baseState.setExecutable("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
baseState.setCommandLineArguments(commandLineArguments);For example, to start Mozilla Firefox with the profile myProfile, type the following:
baseState.setCommandLineArguments("-p myProfile");
baseState.setWorkingDirectory(workingDirectory);
baseState.setExecutablePattern(executablePattern);For example, if you want to specify an executable pattern for the Calculator, type:
baseState.setExecutablePattern("*\\calc.exe");
baseState.setCommandLinePattern(commandLinePattern);Using the command line is especially useful for Java applications because most Java programs run by using javaw.exe. This means that when you create an application configuration for a typical Java application, the executable pattern, *\javaw.exe is used, which matches any Java process. Use the command line pattern in such cases to ensure that only the application that you want is enabled for testing. For example, if the command line of the application ends with com.example.MyMainClass you might want to use *com.example.MyMainClass as the command line pattern:
baseState.setCommandLinePattern("*com.example.MyMainClass");
baseState.setBrowserType(BrowserType.GoogleChrome);
baseState.setUrl(url);For example, type the following:
baseState.setUrl("demo.borland.com/InsuranceWebExtJS/");
baseState.setViewportHeight(viewportHeight); baseState.setViewportWidth(viewportWidth);
new MobileBaseState(connectionString);For information on the connection string, see Connection String for a Remote Desktop Browser or Connection String for a Mobile Device.
baseState.setConnectionString( "moz:firefoxOptions=" + "{" + " \"prefs\": {" + " \"browser.download.dir\":\"C:\\\\Download\\\\\"" + " }" + "};");For additional information, see Setting Options and Capabilities for Web-Driver Based Browsers.