All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.qmetry.qaf.automation.cucumber.ObjectFactoryImpl Maven / Gradle / Ivy

Go to download

Functional test automation framework for web, mobile-web, mobile native and web-service

There is a newer version: 4.0.0-RC3
Show newest version
package com.qmetry.qaf.automation.cucumber;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.impl.LogFactoryImpl;

import com.qmetry.qaf.automation.step.DefaultObjectFactory;
import com.qmetry.qaf.automation.step.ObjectFactory;

import io.cucumber.core.runtime.ObjectFactorySupplier;

/**
 * Object factory implementation for QAF to use cucumber provided object factory
 * that does dependency injection. This class will be used when running your BDD with QAF
 * BDD Factory and you used cucumber object factory that does dependency injection.
 * 
 * @author chirag.jayswal
 *
 */
public class ObjectFactoryImpl implements ObjectFactory {
	private static final Log logger = LogFactoryImpl.getLog(ObjectFactoryImpl.class);

	private ObjectFactorySupplier supplier;

	public ObjectFactoryImpl(ObjectFactorySupplier supplier) {
		this.supplier = supplier;
	}

	@Override
	public  T getObject(Class cls) throws Exception {
		io.cucumber.core.backend.ObjectFactory objectFactory = supplier.get();
		try {
			return objectFactory.getInstance(cls);
		} catch (Exception e) {
			//fall-back
			logger.debug("Unable to crete obect of class["+cls+"] using ["+objectFactory.getClass()+"]. Using default qaf obect factory as fallback");
			return new DefaultObjectFactory().getObject(cls);
		}
	}

	public void setFactory(ObjectFactorySupplier supplier) {
		this.supplier = supplier;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy