Unicode char are getting garbled when ruuning Maven When running the script as a Java program or using TestNG Unicode char is not garbled. But I want to get it run with Maven.
Code:
import org.testng.annotations.Test;
public class TestClass {
@Test
void sample() {
System.out.println("Hello how are you");
System.out.println("乇乂丅尺卂 丅卄工匚匚 vaporwave ォ威嵐");
}
}
Maven version:
PS F:\Java projects\Udemy_Selenium_Java> mvn --version
Apache Maven 3.8.5 (3599d3414f046de2324203b78ddcf9b5e4388aa0) Maven home: F:\Java projects\Dependencies\apache-maven-3.8.5 Java version: 17.0.1, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk-17.0.1 Default locale: en_US, platform encoding: Cp1252 OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
Result when running with Maven and Unicode char garbled :
PS F:\Java projects\Udemy_Selenium_Java> mvn clean test -Dtest="TestClass"
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< org.example:Udemy_Selenium_Java >-------------------
[INFO] Building Udemy_Selenium_Java 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ Udemy_Selenium_Java ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Udemy_Selenium_Java ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ Udemy_Selenium_Java ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 33 source files to F:\Java projects\Udemy_Selenium_Java\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ Udemy_Selenium_Java ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory F:\Java projects\Udemy_Selenium_Java\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ Udemy_Selenium_Java ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 95 source files to F:\Java projects\Udemy_Selenium_Java\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:3.0.0-M6:test (default-test) @ Udemy_Selenium_Java ---
[INFO] Using auto detected provider org.apache.maven.surefire.testng.TestNGProvider
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running TestClass
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Hello how are you
????? ????? ????????? ???
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.706 s - in TestClass
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 11.789 s
[INFO] Finished at: 2022-07-23T20:39:23+05:30
[INFO] ------------------------------------------------------------------------
POM.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>Udemy_Selenium_Java</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.5</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
Working screenshot with TestNG: TestNG Working Sample screenshot