Search code examples
javaseleniumautomationopentest

Trying to use my Java test code with OpenTest


I have installed Opentest on my Ubuntu 16.04 LTS, and want to keep track of my automation code pass/fail success rate. I am able to connect to the localhost server, but am confused after that. I have a java file that I have successfully created that automates a log in function.

I have done my research and found this for the example, but can't seem to find where this package is.

package org.getopentest.selenium;

import org.getopentest.selenium.core.SeleniumTestAction;
import org.getopentest.annotations.TestActionArgument;
import org.getopentest.annotations.TestActionClass;
import org.getopentest.annotations.Type;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

Other Examples:https://github.com/mcdcorp/opentest/tree/master/actor/selenium/src/main/java/org/getopentest/selenium

I can't seem to find where that package is and would like to continue coding in Java versus switching to YAML. If you have any ideas on how I can go about getting my automaton onto Opentest please comment. Thank you.


Solution

  • You only have to write Java code if you want to create new keywords to perform some functionality that is not available out-of-the-box with the OpenTest core packages. This is fairly straightforward: you create a class that inherits from the org.getopentest.base.TestAction class and override the run method to perform the logic of the test action. However, this new keyword that you are creating can only be used from YAML. If you're a skilled Java programmer, you might be tempted to stick with what you know and avoid the YAML approach, but please keep in mind the benefits this approach gives you: increased development speed, increased maintainability and readability, shorter, self-contained tests, ability to easily orchestrate a distributed test or data-driven test and many others.

    Since each test is stored in its own file, it is trivial for you and other members of your team to navigate around them, move them around between directories to re-group/organize them, etc.

    When you need to write more complex logic in a test (loops, conditionals, etc.), you can embed JavaScript code anywhere in the flow of your test using script actions. You can even access the full Java runtime library from JavaScript code, if you need to, although you should only do that as a last resort.

    Please, give YAML a chance. I promise you'll come to appreciate it in no time. However, make sure to use a modern text editor with YAML support. VS Code is perfect in my experience (and also free), but I bet Atom, Sublime or others can do just as well.