How to export Sikuli scripts to java? - testing

I am new to automation and have to use Sikuli, can you all tell me how to export Sikuli script in java also is it possible to integrate those scripts with Selenium....
Thanks in advance.....

"export" scripts to Java is not possible in this sense, since Sikuli scripts are written in Python scripting language and the scripts itself are run using the Jython interpreter (Java base implementation of Python language).
But since the the essential Sikuli features are implemented using Java, you might transcript/translate a script to Java code, since the Sikuli functions are nearly identical on the Python API level and the Java API level.
But if you have more complex Sikuli Scripts, that you want to run from Java code, there are options to do that:
run the script like from command line, but in a subprocess
run the script using Sikuli's ScriptRunner

Related

Code coverage for Robot framework where application written in C++

I have a scenario like this - Application written in hybrid languages (Python, C++ and Java majorly). There are around 100 test cases written in Robot framework to test the application. Now I want to see code coverage of my application. Is there any tool that can work in such scenario?
Thanks in advance.
The same way you would do outside robotframework: Using external code analysis tools. Let me elaborate.
In Python, you can use tools like Coverage (https://pypi.org/project/coverage) to run your testing suite while gathering coverage data. For example, if you usually run your robot test suites using:
robot suites
(supposing you have a "suites" directory with your .robot files) then you would run robot as a Python module over Coverage like this:
coverage run -m robot suites
And you could get your report with:
coverage report
You'll probably need to filter the report (--include option) if you're only interested in code inside a directory. For example, for a directory "myproy" you would do:
coverage report --include *myproy/*
You could use a similar strategy with other Python test coverage tools as long as you figure out how to tweak their execution command to run robot as a module. The same holds for C++ and Java code analysis tools; For example, check the following link for a guide that uses Java with JaCoCo and Maven: https://www.cnblogs.com/z1500592/p/6676646.html

Integrating shell scripts with selenium

I have a situation where we would like to run our Selenium test suite, but
at certain points in the process we would like to execute a shell command
on our machine.
Does Selenium have the capability of executing a shell command and to
receive a response and then to act on those results? Is this possible? If
so, how?
thanks in advance.
You tagged it TestNG meaning you write your Selenium tests in Java. The Selenium framework itself does not have a method to run shell scripts. But Java does, you can just execute commands in your tests and later use the output or input from/for Selenium actions.
Runtime.getRuntime().exec()
Read more:
In the Java documentation: https://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html#exec(java.lang.String[])
How to Run a Shell Command in Java: https://www.baeldung.com/run-shell-command-in-java
Using the output of the Shell command: java runtime.getruntime() getting output from executing a command line program
Selenium is just a library for interacting with web browsers. To strictly answer your question.. the answer is "No, it can not". However, you can easily integrate execution of shell scripts from your test code or framework. How you do that will depend on the language you are using.
Yes you can, but you have to use certain specific libraries along with it in addition to the language you choose eg. If you choose java, you either have to provide repo url via maven or gradle but if you just use python instead since it's highly interpreted, it can pull dynamic content that do pose limitation in Java Selenium, TestNG, PDFBox, POI lib etc. You can deploy a js library of your choice and include that function inside your python code to be invoked via the commands or action that you set your application to.
In short, use Python for purely less troubling dynamic meta extractions, string manipulation, piping output to any other file. Hope that helps.

Katalon - export recorded test script to java/junit

Is there an option to export recorded test script to Java/JUuit(similar to slenium IDE) in Katalon studio? Because the application I'm working on is compatible only with IE; so I couldn't use selenuim IDE. so I'm forced to find someother tools to play/record sessions.
Appreciate your help in advance! Thanks!
As of version 4.8 Katalon Studio does not support export test cases to other frameworks. But if you want more control on your project, you can modify test cases directy in the Script Mode using Groovy/Java. It is also possible to import 3rd party Java libraries to your project if need be.
After creating the test case with some steps, we could view the script and adjusting it, for examples: https://docs.katalon.com/display/KD/Test+Case+Script+View
From here, we could add more codes to handle our testing flows.
However, since the code uses some Katalon libraries, so it might not posible to copy the script and run somewhere else.
you can export code into java/ python using Katalon browser plugin. Just import existing test case recording into the plugin and click on "export" option.
Yes you can export it Java (Junit, TestNg), python, C#, Ruby.
Download the chrome pluging
https://chrome.google.com/webstore/detail/katalon-recorder-selenium/ljdobmomdgdljniojadhoplhkpialdid
Follow the guide screen
Create a Maven Java project, create a new Test class file and copy paste the code and run the project to test the browser test.
Done !
You can record your test and export in the following language and framework:
C#
Java
Python
Robot Framework
Ruby
It is an extension for chrome like Selenium IDE
you can find it here

How can we use Sikuli with Selenium in Python?

I know that how we can use Sikuli in Java. But I have some code in Python which is automating a web application, and I want to use Sikuli in it. I searched a lot on the Internet about how we can use Sikuli in Python. But I did not find any good resource related to it.
How can I import Sikuli script in a Python project in Eclipse? When I added the sikuli-script.jar file in the Python path in Eclipse and when I am trying to use
import * from sikuli
Then I am getting "there is no such type of module named sikuli".
Sikuli is a tool written in Java and hence you can't use it in your Python code as is. Instead you have the option to use it within a Jython environment, that provides you the Python syntax and enables running jar packages. If you are not using many third party Python libraries and mainly stick to the generic functionality, you shouldn't get into too much trouble transferring from pure Python to Jython.
There are clear instructions of how to use Sikuli with Jython on SikuliX official website. If you have any related questions, you can post the here.

Unable to use few Selenium commands while writing scripts

There are some Selenium commands that I am unable to use in a script that I'm writing and I do not have any idea as to whether I am missing an import of required library files or packages.
For example - selenium.browserbot, selenium.waitForElementPresent.
I am using Selenium IDE to record the script and working in Eclispe Junit platform.
Use isElementPresent instead of waitForElementPresent.