I have one bundle Activator class and some of codes there.
I need to use #Autowired inside my bundle activator class. It is not working.
Here is my bundle Activator class,
public class ProviderActivator implements BundleActivator {
#Autowired
public TestingClass testingClass;
public void start(final BundleContext bundleContext) throws Exception {
System.out.println("bundle starter!!!!!!!!!!!!!!" +testingClass );
}
}
testingClass SOP is null. Spring context scanning added in spring-context.xml.
here my suggestion is,
the bean injected after bundleActivator class loaded.
How to prevent that? why the bean is null when startup bundle class?
Why would you even expect this to work? The activator class is instantiated by the OSGi Framework, and #Autowired is not an OSGi feature.
Related
I am using appium 6.1.0 which has <T extends WebElement> T findElement(By by); method on WebDriver class. Somewhere in automated tests I have following APIs -
protected String getText(WebElement element) {
return getText(element, Config.LOAD_WAIT);
}
and
protected String getText(By by) {
return getText(by, Config.LOAD_WAIT);
}
And getText method is invoked by test as -
public String getFullName() {
return getText(driver.findElement(By.cssSelector(".basicDataSection)))
}
But using WebDriver class from appium dependency throws exception on getFullName method about method call being ambiguous since it matches both getText(WebElement element) and getText(By by) How is this possible since findElement return type is T extends WebElement in WebDriver class in appium dependency?
On a different note, there is also WebElement findElement(By by); API in WebDriver class in selenium-api but after adding appium dependency method in my project they have begun to refer to WebDriver class from appium dependency and not from selenium-api dependency. Unfortunately WebDriver api in both classes have same package org.openqa.selenium.
I am not sure if WebDriver class from appium and selenium-api can be used interchangeably as they have different automation purpose (i.e. mobile app and web app). If WebDriver class from appium and selenium-api can not be used interchangeably then is there a way to enforce to use WebDriver class from selenium-api dependency and not from appium dependency?
Consider using MobileElement instead of WebElement to avoid clashes with underlying Selenium API
Make sure to have only appium-java-client library in your project dependencies, Appium 6.1.0 assumes Selenium 3.12.0 so you have to use exactly this version of Selenium in order to avoid Jar Hell so I would recommend using dependency management solution like Maven or Gradle to automatically resolve Appium Java client library and all its transitive dependencies. See Code Examples -> Appium with Java for comprehensive information and sample projects
I'm new to Selenium I have exported TestNG suite to jar file using the Eclipse export option but am unable to run it.
Inorder to run a jar file you need to have a class with main method pointed to your Launch configuration while exporting.
you can run TestNG programmatically by creating this main method,
public static void main(String[] args) {
TestListenerAdapter tla = new TestListenerAdapter();
TestNG testng = new TestNG();
testng.setTestClasses(new Class[] { Run2.class });
testng.addListener(tla);
testng.run();
}
Add this main method class to your Launch Configuration while exporting the jar in eclipse.
Refer this testNG doc for more information : Run testNG programmatically
If you are using maven-jar-plugin to export jar make sure you have added your mainClass in manifest.
I fail to correctly reference a service interface with the #Reference Annotation.
public class TestServiceProcessor implements Processor {
#Reference
private TestService testService;
The Service is up and running on the Karaf Instance and i can reference it with the blueprint file which does work fine.
<bean id="translateOIDs"
class="com.test.TestServiceProcessor">
<property name="TestService" ref="testservice" />
</bean>
<reference id="testservice"
interface="com.test.TestService"/>
The Service has been set up with the OSGI Component Annotations.
I already installed the scr feature and camel-scr on Karaf.
I tried using the field strategy as well as the Event Strategy.
Do i need to further configure the Karaf Instance or am i using the #Reference Annotation in a wrong way?
First you need to install the scr feature to enable declarative services. I guess you mean this with "src" feature.
Apart from this #Reference only works in DS components. So you class TestServiceProcessor must be annotated with #Component ... but then it can not be used in blueprint. DS and blueprint are mutually exclusive.
What you can do instead is leverage the http://aries.apache.org/modules/blueprint-maven-plugin.html.
In this case you need to annotate the bean class with #Named and do the inject with #Inject. You can then also reference annotated beans from the regular blueprint context by their id which can be set using #Named("yourid").
I've been reading in the Allure wiki however I do not seem to be able to get started with Allure.
I have an IntelliJ project which I use to run JUnit tests with Selenium. I want to add Allure for better feedback after test runs. However I've not been able to understand how Allure would integrate with the rest of my project.
On the wiki page for JUnit it looks like Allure with JUnit only supports maven projects? How can I set up allure to work with an IntelliJ project?
I want to add Allure for better feedback after test runs
It is strange that you don't have a build tool.
But for single test (as you mention) following will work.
Dependencies - you need aither allure-junit-adaptor or allure-testng-adaptor
Allure implements test listener, which should be added to test runner:
For TestNG it happens automatically (once you add adaptor dependency).
For JUnit you should add listener manually. I don't know how to add it to Intellij Idea JUnit runner, but you can always run tests programmatically:
public static void main(String[] args) {
JUnitCore runner = new JUnitCore();
runner.addListener(new AllureRunListener());
runner.run(CalculatorTest.class);
}
That will generate XML report in target/allure-results folder.
If you need advanced Allure features like file attachments and test steps you need another dependency (aspectjweaver) and according JVM args, e.g.
-javaagent:lib/aspectjweaver-1.8.7.jar
To generate HTML report from existing XML report you can:
either use Allure CLI (requires tool installation http://wiki.qatools.ru/display/AL/Allure+Commandline)
or use 'mvn site' on existing project (e.g. https://github.com/allure-examples/allure-junit-example)
Open your HTML report in Firefox (or look here how to open locally generated report in Chrome).
To have allure-results after launching JUnit4 tests from IDE using context menu or controls on the gutter I use #RunWith anntotation where I set my custom runner with AllureJUnit4 listener.
CustomRunner class
package ru.atconsulting.qa.system.junit4runners;
import io.qameta.allure.junit4.AllureJunit4;
import org.junit.runner.notification.RunNotifier;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.InitializationError;
public class CustomRunner extends BlockJUnit4ClassRunner {
/**
* Creates a BlockJUnit4ClassRunner to run {#code klass}
*
* #param klass
* #throws InitializationError if the test class is malformed.
*/
public CustomRunner(Class<?> klass) throws InitializationError {
super(klass);
}
#Override
public void run(RunNotifier notifier) {
notifier.addListener(new AllureJunit4()); //just add listener
super.run(notifier);
}
}
Using #RunWith annotation in test classes
#RunWith(CustomRunner.class)
public class ExampleSuite {
#Test
public void testExample() {
....
}
}
I am trying to use RestEasy with Spring Boot. I need to configure it so it uses RestEasy's SpringContextLoaderListener instead of the Spring Boot default. I tried adding the listener in the config class but I get an error saying that a Context Loader Listener already exists.
Is there a way I can do this?
Rather than trying to use RESTEasy's SpringContextLoaderListener, you should be able to get this to work by dependency on org.jboss.resteasy:rest easy-spring and importing its springmvc-resteasy.xml configuration:
package sample.resteasy;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
#Configuration
#ComponentScan
#EnableAutoConfiguration(exclude=WebMvcAutoConfiguration.class)
#ImportResource("classpath:springmvc-resteasy.xml")
public class SampleResteasyApplication {
public static void main(String[] args) {
SpringApplication.run(SampleResteasyApplication.class, args);
}
}
Note that WebMvcAutoConfiguration has been disabled. This is to work around a problem with RESTEasy's SpringBeanProcessor that causes a failure when it encounters a non-public #Bean method. WebMvcAutoConfiguration declares such a method so, to get RESTEasy to work, it has to be disabled.