Using Assets in Multiple Projects

In Silk4J, image assets, image verifications, and object maps are referred to as assets. If you want to use assets outside of the scope of the project in which they are located, you need to add a direct project dependency from the project in which you want to use the assets to the project in which the assets are located. When you are playing back tests from Eclipse, all dependent projects are added to the classpath for the test execution, and therefore Silk4J can find the assets in the dependent projects.

During replay, when an asset is used, Silk4J firstly searches in the current project for the asset. The current project is the JAR file which contains the test code that is currently executed. If Silk4J does not find the asset in the current project, Silk4J additionally searchesall other projects in the classpath.. If the asset is still not found, Silk4J throws an error.

If assets with the same name exist in more than one project, and you do not want to use the asset that is included in the current project, you can define which specific asset you want to use in any method that uses the asset. To define which asset you want to use, add the asset namespace as a prefix to the asset name when calling the method. The asset namespace defaults to the project name.

Note: When you start working with Silk4J, the asset namespace option is added to the silk4j.settings file of every Silk4J project in your workspace that has been created with a previous version of Silk4J.

Example: Adding a project dependency

If the project ProjectA contains a test that calls the following code:
window.imageClick("imageAsset");
and the image asset imageAsset is located in project ProjectB, you need to add a direct project dependency from ProjectA to ProjectB.

To add a project dependency in Eclipse, right-click the project and select Properties. Select Java Build Path, click on the Projects tab, and add your project here.

Note: Using Project References instead of Java Build Path does not work.

Example: Calling a specific asset

If ProjectA and ProjectB both contain an image asset with the name anotherImageAsset, and you explicitly want to click the image asset from ProjectB, use the following code:
window.imageClick("ProjectB:anotherImageAsset")