Run Sikuli commands on Katalon-Studio - sikuli

I'm trying to run a test that contains Sikuli methods in it via Katalon-Studio.
I added the necessary libraries but still getting this error when it tries to execute the Sikuli command:
[error] ResourceLoaderBasic: checkLibsDir: libs dir is not on system path: C:\Users\roinr\git\QA\Drivers\libs
[action] ResourceLoaderBasic: checkLibsDir: Please wait! Trying to add it to user's path
[info] runcmd: reg QUERY HKCU
[info] runcmd: reg QUERY HKEY_CURRENT_USER\Environment /v PATH
[error] ResourceLoaderBasic: checkLibsDir: Logout and Login again! (Since libs folder is in user's path, but not activated)
[error] Terminating SikuliX after a fatal error! Sorry, but it makes no sense to continue!
If you do not have any idea about the error cause or solution, run again
with a Debug level of 3. You might paste the output to the Q&A board.
This is my script:
import internal.GlobalVariable as GlobalVariable
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.sikuli.script.Key;
import org.sikuli.script.Screen;
//Initializing server
System.setProperty("webdriver.chrome.driver", "C:/selenium/chromedriver.exe");
//Initializing variables
ChromeDriver wd = new ChromeDriver();
WebDriverWait wait = new WebDriverWait(wd,10);
Screen s = new Screen();
wd.manage().window().maximize();
wd.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
System.out.println("*** Login Sikuli ***");
wd.get("https://autoqa-materials-zone.firebaseapp.com/login");
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[2]/div/input")));
wd.findElement(By.xpath("//div[2]/div/input")).click();
try { Thread.sleep(1000l); } catch (Exception e) { throw new RuntimeException(e); }
s.paste("<USERNAME>");
try { Thread.sleep(1000l); } catch (Exception e) { throw new RuntimeException(e); }
s.type(Key.TAB);
try { Thread.sleep(800l); } catch (Exception e) { throw new RuntimeException(e); }
s.paste("<PASSWORD>");
try { Thread.sleep(1000l); } catch (Exception e) { throw new RuntimeException(e); }
wd.findElement(By.xpath("//form[#id='form']//paper-button[.='login']")).click();
try { Thread.sleep(5000l); } catch (Exception e) { throw new RuntimeException(e); }
wd.quit();
Hope you can help me with that,
thanks.

Related

Junit parallel tests logs is messed up with each other

I have some test classes and methods which running parallel.
I'm using log4j2 for logging, however the log outputs to the console is messed up with each other.
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
#Execution(ExecutionMode.CONCURRENT)
public class TestClass1 {
Logger log = LogManager.getLogger();
#Test
public void test1() {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
log.info("Performing test1 method in " + this.getClass().getName());
}
#Test
public void test2() {
log.info("Performing test2 method in " + this.getClass().getName());
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
The expected to see output in test1 TestClass1 - Performing test1 method in TestClass1
and in tests2 TestClass1 - Performing test2 method in TestClass1
Current state: Both outputs printed in first or second test together or only one tests printed.
It's look like still existing issue on IntelliJ IDEA
IntelliJ test runner mixes output from different tests when TestNG parallel is used
Regarding to opened bug in JetBrains the issue will not be fixed someday.
I tried to use TestReporter injection mentioned in bug below, however it also doesn't work.
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestReporter;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
#Execution(ExecutionMode.CONCURRENT)
public class TestClass1 {
#Test
public void test1(TestReporter testReporter) {
testReporter.publishEntry("test1 started");
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
#Test
public void test2(TestReporter testReporter1) {
testReporter1.publishEntry("test2 started");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}

How to import MySQL using Gradle and connect into JavaFX

I'm using IntelliJ IDEA and JavaFX 10 for my practice learning. I want to connect MySQL and import it using Gradle.
I found multiple example in internet but I din't found any latest, most of the function is already depreciated and reading so much different example makes me confused.
You may want to read first the official documentation instead of reading multiple example.
I assume that you are beginner.
1.) First thing to do is to Download the MySQL Installer to intall the Server into your machine. Remember that things won't work without this.
During the installation you will need to set your Server PORT, root password or add a new user, just remember the Server PORT and root Password and leave things in default.
2.) Go to Maven Central. We need to import the MySQL Connector. In order to import the MySQL Connector into Gradle we need to get the correct group, name and version for it.
You notice that in Maven Central there are multiple selection on how you can import the jar into your project, this time we want to import it using Gradle,
so you have to choose the Gradle and copy the code: compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.11'
NOTE - In order to avoid problems, just always choose and use the latest version of MySQL Installer and MySQL Connector, at the moment the latest version is 8.0.11.
3.) In IntelliJ IDEA, in order to import in Gradle, in your project there is build.gradle click it to open then paste the code you copied in dependencies.
it should look like:
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.11'
}
4.) Create a class where you want to connect into MySQL, the below code is my example.
Main.Class
import java.lang.reflect.InvocationTargetException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Main {
public static void main(String[] args){
Connection conn = null;
String user = "whatEverUserNameYouSetup";
String password = "whatEverPasswordYouSetup";
String database = "whatEverTheNameOfYourDatabase";
int port = 3306; //default port, change it depending on your setup
try {
Class.forName("com.mysql.cj.jdbc.Driver").getConstructor().newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:" + port + "/" + database, user, password);
// Do something with the Connection
} catch (SQLException ex) {
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
NOTE: The documentation is your friend.
UPDATE: If you run on error something like
Wed Dec 09 22:46:52 CET 2015 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
then you need to set useSSL to false, the code will be look like:
import java.lang.reflect.InvocationTargetException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
public class Main {
public static void main(String[] args){
Connection conn = null;
Properties properties = new Properties(); //I use Properties to make things easer.
properties.setProperty("user", "root");
properties.setProperty("password", "YourPassword");
properties.setProperty("useSSL", "false"); //Set useSSL to false to solve the problem.
try {
Class.forName("com.mysql.cj.jdbc.Driver").getConstructor().newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306", properties);
// Do something with the Connection
} catch (SQLException ex) {
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}

unreported exception IOException; must be caught or declared to be thrown

I have a question , why does java keeps throwing that exception ! Is the problem with the stream ? because I handeled all IOExceptionS !
[[jio0yh.java:12: error: unreported exception IOException; must be
caught or declared to be thrown]]>>
That's the exception that I'm getting!
here is my code
import java.io.*;
public class jio0yh{
public static void main(String[]args){
FileInputStream OD=null;
try{
File f=new File("Binary.dat");
OD= new FileInputStream(f);
byte[]b=new byte[(int)f.length()];
OD.read(b);
for(int i=0;i<b.length;i++)
System.out.println(b[i]);
} catch(FileNotFoundException e){
System.out.println(e.getMessage());
} catch(IOException e){
System.out.println(e.getMessage());
OD.close();
}
}
}
The OD.close(); in your IOException catch block is also susceptible to throwing another IOException.
You should surround the final OD.close() in a finally block:
// ... Any previous try catch code
} finally {
if (OD != null) {
try {
OD.close();
} catch (IOException e) {
// ignore ... any significant errors should already have been
// reported via an IOException from the final flush.
}
}
}
Refer to the following for a more thorough explanation:
Java try/catch/finally best practices while acquiring/closing resources

Apache Drill - DrillStartupException with CustomAuthenticaor

I tried creating a custom authenticator with Drill 1.5.0 by creating jar based on below source code and drill configuration. I placed the jar in $DRILLHOME/jars/
drill-override.conf File :
drill.exec: {
cluster-id: "drillbits1",
zk.connect: "host1:2181,host2:2181,host3:2181"
security.user.auth: {
enabled: true,
packages += “myorg.drill.security",
impl: “sso"
}
}
DrillMyUserAuthenticator Class:
package myorg.drill.security;
import myorg.drill.security.SSOFilter;
import myorg.drill.security.SecurityServiceException;
import org.apache.drill.common.config.DrillConfig;
import org.apache.drill.exec.exception.DrillbitStartupException;
import org.apache.drill.exec.rpc.user.security.UserAuthenticationException;
import org.apache.drill.exec.rpc.user.security.UserAuthenticator;
import org.apache.drill.exec.rpc.user.security.UserAuthenticatorTemplate;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
#UserAuthenticatorTemplate(type = “sso")
public class DrillMyUserAuthenticator implements UserAuthenticator {
private String ipAddress;
public void setup(DrillConfig drillConfig) throws DrillbitStartupException {
try {
ipAddress= InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException e) {
e.printStackTrace();
throw new DrillbitStartupException(e);
}
}
public void authenticate(String userName, String password) throws UserAuthenticationException {
try {
SSOFilter.setSourceAddress(ipAddress);
SSOFilter.authenticate(userName, password);
} catch (SecurityServiceException e) {
e.printStackTrace();
throw new UserAuthenticationException(e.getMessage());
}
}
public void close() throws IOException {
}
}
And I am getting below exception:
exception in thread "main" org.apache.drill.exec.exception.DrillbitStartupException: Failure while initializing values in Drillbit.
at org.apache.drill.exec.server.Drillbit.start(Drillbit.java:277)
at org.apache.drill.exec.server.Drillbit.start(Drillbit.java:261)
at org.apache.drill.exec.server.Drillbit.main(Drillbit.java:257)
Caused by: org.apache.drill.exec.exception.DrillbitStartupException: Failed to find the implementation of 'org.apache.drill.exec.rpc.user.security.UserAuthenticator' for type ’sso'
at org.apache.drill.exec.rpc.user.security.UserAuthenticatorFactory.createAuthenticator(UserAuthenticatorFactory.java:103)
at org.apache.drill.exec.rpc.user.UserServer.(UserServer.java:80)
at org.apache.drill.exec.service.ServiceEngine.(ServiceEngine.java:79)
at org.apache.drill.exec.server.Drillbit.(Drillbit.java:89)
at org.apache.drill.exec.server.Drillbit.start(Drillbit.java:275)
Please let me know if I am missing something with the config or code.
I followed Drill's documentation to create this.
Turns out be a documentation issue on Drill Side. https://issues.apache.org/jira/browse/DRILL-4461
Above Jira has the solution to the problem.New jar for the custom authenticator should be created with drill-module.conf in order for the classpath scanner to pick it up
drill: {
classpath.scanning: {
packages: [
"myorg.drill.security"
]
}
}

Access is denied exception while running autoit exe file from selenium java code

In my selenium webdriver code i am calling an autoit exe for handling an windows authentication dialog . But when i execute the code it it throwing exception
the code is
try {
String s2 = System.getProperty("user.dir");
String path2 = s2 + "\\src\resources\\AuthHandler.exe";
java.lang.Runtime.getRuntime().getRuntime().exec(path2);
} catch (IOException e1) {
e1.printStackTrace();
}
The exception is
java.io.IOException: Cannot run program
"D:\ProjCode\workspace\xxxx\src": CreateProcess error=5, Access is
denied
What might be the reason for this . i tried
Process p = new ProcessBuilder(path2).start();
but getting the same result .
The exe is having execute privilege, when i double click it, it is working fine .
try {
String s2 = System.getProperty("user.dir");
String[] myEXEpath = new String[]{ s2 + "\\src\\resources\\"+"MyExe.exe","firefox" };
java.lang.Runtime.getRuntime().getRuntime().exec(myEXEpath);
} catch (IOException e1) {
e1.printStackTrace();
}