Skip to content

lizaiv77/test-drop-in-framework

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

test-drop-in-framework

The ContextProvider helps the owner of a test project and her partner teams, be them either inside or outside the company, to run the very same tests provided by the owner in every team's test environment. In essence, it allows to make sure that the code gets run in a proper context with the proper test cases without having to modify or rewrite any customer code or test cases, etc.

When the owner runs her tests, the owner leaves the switch in "owner mode" aka "default mode". If a partner team runs the tests, they flip the switch to their test context.

Requirements

To use this project the following requirements have to be met:

  • Java 1.8
  • TestNG and Selenium WebDriver on the class path

Recommended

  • Maven to resolve dependencies on TestNG and Selenium
  • If you are running in Eclipse, you will want the m2e (Maven Integration for Eclipse) plugin.

Please note: if you want to use Microsoft Internet Explorer for test execution, you have to explicitly add dependencies on JNA and JNA-Platform.

Development

  1. Pull the right branch of test-drop-in-framework: a. When your project is based on WebDriver 3.x or newer, pull from branch 'master' b. When your project is based on WebDriver 2.x, pull from branch 'selenium2'
  2. Run mvn eclipse:eclipse to generate .project file and download required jars for development in Eclipse.
  3. Run mvn clean to install any dependencies.
  4. Start up eclipse, import project test-drop-in-framework.
  5. Compile project and create jar file: a. When your project is based on WebDriver 3.x or newer, run mvn compile jar:jar which creates jar file target/test-drop-in-framework-2.0.0.jar b. When your project is based on WebDriver 2.x, run mvn compile jar:jar -f pom.xml which creates jar file target/test-drop-in-framework-selenium2-2.0.0.jar
  6. Deploy jar file to local repository: a. When your project is based on WebDriver 3.x or newer, run mvn install:install-file -Dfile=target/test-drop-in-framework-2.0.0.jar -DpomFile=pom.xml b. When your project is based on WebDriver 2.x, run mvn install:install-file -Dfile=target/test-drop-in-framework-selenium2-2.0.0.jar -DpomFile=pom.xml

Please note: the framework has to prohibit context switching during runtime. Therefore it is not possible to run both test classes via "mvn test" and have all tests passing!

  1. Run mvn -Dtest=TestDefaultContext test to run all tests provided for testing default context.
  2. Run mvn -Dtest=TestCustomContext test to run all tests provided for testing custom context.

Prepare your test project

  1. Add the test drop-in framework jar created in Development step 5 to your build path.
  2. In your test project create a package which contains your test context interfaces and the test context implementation class. Recommended package name: dropin.custom.<company-name>
  3. In this package define an interface which describes the context as per your needs.
// Example context interface:
public interface TestContext extends BaseContext {
	IData<String> data();
	ILogger logger();
	IReport report();
	// always provide a custom initialization method
	void initialize(TestCase testCase);
	// helper classes
	WebDriverHelper wh();
}
  1. Create the various interfaces, e.g. IData:
// BaseData<T> is provided by test-drop-in-framework
public interface IData<T> extends BaseData<T> {
	T getCommonData(String key);
	void setCommonData(String key, T value);
}
  1. Create classes implementing the various interfaces.
  2. Create the class implementing the test context defined in step 3.

Initialization of the TestContext

The TestContext interface (see example above) requires implementation of then initialize(testCase) method, where the objects stored in the context get initialized. A good place is in a method run during initialization of a test class or in methods annotated with @BeforeClass if you are using TestNG or JUnit.

Use the test context in your test project

  1. Where-ever in your test project you need to access something stored in the test context, first get the handle to the TestContext (see interface example above) this way:
TestContext tc = ContextProvider.getTestContext(TestContext.class);
  1. Access the data in the context:
String value = tc.data().getCommonData("mykey");

How to toggle between Test Context implementations?

The first call of method

ContextProvider.getTestContext(final Class<T> type)

will "freeze" the interface type and the implementation class.

If the test context implementation is in the same package as the test context interface and the class name has "Impl" as a postfix to the interface name, the call to getTestContext() will try and instantiate this so-called "default context" class unless it is overridden by a "custom context" class.

To use a so-called "custom context" you have to set the system property

-Ddropin.context.implclassname=[your test context impl class]

All following calls to that method will return the very same context class instance.

Please note: switching context during test execution may be fatal if information of previous context has been cached in calling classes. Therefore the getTestContext() method will prohibit any attempts to switch context.

Filing bugs

If you find any bugs in Test Drop-in Framework, please open a new issue on GitHub and add as many details as possible, but at least the following:

  • Expected outcome
  • Actual outcome
  • Is reproducible? (Always, Randomly, etc.)
  • Reproducer scenario
  • Your dev environment (Linux, Mac OS, version, etc.)

Bug Review SLA

After submitting a bug, you can expect to hear back an answer within the next five working days.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages

  • Java 100.0%