Error while converting java project to maven project - selenium

I just installed eclipse for Learning selenium automation i have added java environment variable but after converting java to maven project its giving me some error as follows:

The <maven-compiler-plugin> looks error-prone. You can update it as:
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
Additionally you need to indent the <dependency> properly as follows:
<dependencies>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.3.0</version>
</dependency>
</dependencies>

Related

#Step is not reported

I'm new to Allure,
I work with playwright + jave,
I'm trying to add steps to the report, but it seems that #Step Anotation is not reported in the allure test report,
I added to the pom:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<argLine>
-javaagent:"${settings.localRepository}\org\aspectj\aspectjweaver\${aspectj.version}\aspectjweaver-${aspectj.version}.jar"
</argLine>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/AllTests.tng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
#Test/#Attachment works well, only the #Step.
thanks!

When running via maven, my tests are not found in the junit project

screenshot 1
As in the screenshot 1 I'm trying to run my set of autotests, the build works successfully, but not a single test is defined.
screenshot 2
Screenshot 2 shows the result after running through maven
If you run tests separately, through "run test", but everything starts and runs according to the script
my POM file:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.2.0</version>
</dependency>
</dependencies>
<configuration>
<additionalClasspathElements>
<additionalClasspathElement>src/test/java/</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
</plugin>
</plugins>
</build>`
I want that tests were defined in all classes.
I tried to play with the pom file, apparently there are problems in it, but nothing happens.
link to project
i fix problem
my pom:
<?xml version="1.0" encoding="UTF-8"?>
4.0.0
<groupId>org.example</groupId>
<artifactId>Test_Framework</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<selenium.version>4.6.0</selenium.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.9.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>

Webflux + security with spring native - NoClassDefFoundError: WebMvcConfigurer

This is about spring native, I'm facing the same issue in every web flux project I'm working on. I'm not able to generate the native image. Could anyone help please?
I'm working on a Mac (Catalina 10.15.6 (19G73)) and using OpenJDK Runtime Environment GraalVM CE 21.0.0.2 (build 11.0.10+8-jvmci-21.0-b06)
The error I'm getting is:
Fatal error:java.lang.NoClassDefFoundError: org/springframework/web/servlet/config/annotation/WebMvcConfigurer
Error: Image build request failed with exit status 1
This are my dependencies:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.5</version>
<relativePath />
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.experimental</groupId>
<artifactId>spring-native</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>com.nimbusds</groupId>
<artifactId>nimbus-jose-jwt</artifactId>
<version>9.9</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<!-- Customize Spring Boot classifier, useful in order to avoid a clash between Spring Boot repackaging and native-image-maven-plugin -->
<classifier/>
<!-- Customize native-image arguments with this property -->
<native.build.args></native.build.args>
<!-- `tiny` builder allows small footprint and reduced surface attack, you can also use `base` (the default) or `full` builders to have more tooling available in the image for an improved developer experience -->
<!-- TODO Bring back "paketobuildpacks/builder:tiny" before 0.10.0 release -->
<builder>dmikusa/graalvm-tiny</builder>
<spring-native.version>0.9.2</spring-native.version>
<project.encondig>UTF-8</project.encondig>
<project.build.sourceEncoding>${project.encondig}</project.build.sourceEncoding>
<project.reporting.outputEncoding>${project.encondig}</project.reporting.outputEncoding>
<java.version>11</java.version>
<maven.compiler.target>${java.version}</maven.compiler.target>
<maven.compiler.source>${java.version}</maven.compiler.source>
<spring-cloud.version>2020.0.2</spring-cloud.version>
<maven.compiler.plugin.version>2.3.2</maven.compiler.plugin.version>
<maven.resources.plugin.version>2.6</maven.resources.plugin.version>
<maven.dependency.plugin.version>2.8</maven.dependency.plugin.version>
<maven.deploy.plugin.version>2.7</maven.deploy.plugin.version>
<maven.release.plugin.version>2.5.3</maven.release.plugin.version>
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
<jackson.version>2.12.0</jackson.version>
<jackson-bom.version>${jackson.version}</jackson-bom.version>
<jacoco.version>0.8.5</jacoco.version>
<kotlin.version>1.4.20-RC</kotlin.version>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>${classifier}</classifier>
<image>
<builder>${builder}</builder>
<env>
<BP_NATIVE_IMAGE>true</BP_NATIVE_IMAGE>
<BP_NATIVE_IMAGE_BUILD_ARGUMENTS>${native.build.args}</BP_NATIVE_IMAGE_BUILD_ARGUMENTS>
</env>
</image>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.experimental</groupId>
<artifactId>spring-aot-maven-plugin</artifactId>
<version>${spring-native.version}</version>
<executions>
<execution>
<id>test-generate</id>
<goals>
<goal>test-generate</goal>
</goals>
</execution>
<execution>
<id>generate</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.graalvm.nativeimage</groupId>
<artifactId>native-image-maven-plugin</artifactId>
<version>21.1.0</version>
<configuration>
<imageName>${project.artifactId}</imageName>
<buildArgs>${native.build.args}</buildArgs>
</configuration>
<executions>
<execution>
<goals>
<goal>native-image</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.experimental</groupId>
<artifactId>spring-native</artifactId>
<version>${spring-native.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<profiles>
<!-- Enable building a native image using a local installation of native-image with GraalVM native-image-maven-plugin -->
<profile>
<id>native-image</id>
<properties>
<!-- Avoid a clash between Spring Boot repackaging and native-image-maven-plugin -->
<classifier>exec</classifier>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.graalvm.nativeimage</groupId>
<artifactId>native-image-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>
</profiles>
I'm not happy with it, but this is a workaround. Adding the following piece of code in the pom.xml file:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
And add in the properties file the following property:
spring.main.web-application-type=REACTIVE

How to install TestNG in Visual studio code

Can someone please suggest me how to install testng in visual studio code?
Things i have done so far :
1. Added below xml in POM
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.10</version>
<scope>test</scope>
</dependency>
#Sowjanya H M try adding the Java Test Runner extension. it supports running both junit and testng tests. If you have your pom setup correctly, you can execute all tests in your project by selecting your pom.xml and in the command dropdown selecting Run Code. I have a later version of testng in my pom dependencies section:
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
</dependency>
then in your build section, you should have configuration plugins for maven-surefire and your testng xml files. something like:
<build>
<resources>
<resource>
<directory>src/test/resources</directory> #not required
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<configuration>
<!-- testng xml files for test execution -->
<suiteXmlFiles>
<suiteXmlFile>resources/sample.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>

Maven bundle packaging problem, known as MNG-4338

I'm having trouble with the maven-bundle-plugin:
I want to deploy my project as a osgi bundle, wherefore I use the packaging as bundle.
But it seems that the pom does not know a packaging as a bundle. Here you can see my pom.xml:
<project ...>...
<packaging>bundle</packaging>
<version>1.0.0</version>
<name>Simple CXF project using spring configuration</name>
<properties>
<cxf-version>2.4.2</cxf-version>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<version>2.3.5</version>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
<Bundle-Name>${project.name}</Bundle-Name>
<Bundle-Version>${project.version}</Bundle-Version>
<Export-Package>demo.hw.server</Export-Package>
<Bundle-Activator>demo.hw.server.Activator</Bundle-Activator>
<Require-Bundle>org.apache.cxf.bundle</Require-Bundle>
</instructions>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf-version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf-version}</version>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.osgi.core</artifactId>
<version>1.4.0</version>
</dependency>
</dependencies>
</project>
They say, this bug has already been fixed (http://jira.codehaus.org/browse/MNG-4338), but to me it seems it hasn't. Has anyone encountered this problem before and found a solution?
The Error message is like this:
[INFO] Scanning for projects...
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR] The project com.talend.liugang.cxf:java_first_jaxws:1.0.0 (C:\Users\Andreas\workspace\java_first_jaxws\pom.xml) has 1 error
[ERROR] Unknown packaging: bundle # line 7, column 13
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
Best regards,
saen
Given your pom example above, you should just move the maven-bundle-plugin outside of the <pluginManagement> node. <pluginManagement> is normally used for inheritance purposes in parent poms. The bundle packaging type is provided by the maven-bundle-plugin (which is why you need <extensions>true</extensions>), so this plugin is required to be outside <pluginManagement> in this case.
<project ...>...
<packaging>bundle</packaging>
<version>1.0.0</version>
<name>Simple CXF project using spring configuration</name>
<properties>
<cxf-version>2.4.2</cxf-version>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<version>2.3.5</version>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
<Bundle-Name>${project.name}</Bundle-Name>
<Bundle-Version>${project.version}</Bundle-Version>
<Export-Package>demo.hw.server</Export-Package>
<Bundle-Activator>demo.hw.server.Activator</Bundle-Activator>
<Require-Bundle>org.apache.cxf.bundle</Require-Bundle>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf-version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf-version}</version>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.osgi.core</artifactId>
<version>1.4.0</version>
</dependency>
</dependencies>
</project>
Yeap, the issue is that <groupId>org.apache.felix</groupId> needs to be outside of the <pluginManagement>.
I see a similar issue. It occurs to me that it happens when the group id ends like the artifact id starts. I try to bundle something like that:
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api.plugin</artifactId>
The slf4j from the artifact id is deleted at it ends up like: org.slf4j.api.plugin in the Manifest as symbolic name.