3

Is there any way that we can directly use .side file or html file generated by Selenium IDE in eclipse instead of using export Code option for Java?

I don't want to use the Export Code option rather want to find out the ways by which we can use the .side file directly.

Parul Singh
  • 41
  • 1
  • 1
  • 5

2 Answers2

2

You can run .side files, or suites of tests, from the command line using the Selenium IDE command line runner

You can now run all of your Selenium IDE tests on any browser, in parallel, and on a Grid without needing to write any code.

Once everything's installed, running your tests is a simple matter of calling selenium-side-runner from the command-line followed by the path to the project file saved earlier.

selenium-side-runner /path/to/your-project.side

If you have multiple .side files you can use a wildcard (e.g., /path/to/*.side).

When you run this command it will launch your tests in parallel, in multiple browser windows, spread across n processes

Community
  • 1
  • 1
Tony
  • 9,672
  • 3
  • 47
  • 75
0

You want to read and run each element of the .side file in Java, convert this python code in Java. You will be able to catch each step and do selenium method as you want, log each step etc...

import json

with open("your_file.side", "r") as f:
    side_dict = json.load(f)

then you can catch all elements with a code like this :

for test in side_dict["tests"]:
    if test["name"] == test_case_name:
        for command in test["commands"]:
            target = command["target"]
            print(f"""command : {command["command"]}""")
            print(f"target : {target}")

Maybe this code will run in java :

import java.io.FileReader;
import java.io.IOException;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

public class SideFileParser {
    public static void main(String[] args) throws IOException, ParseException {
        JSONParser parser = new JSONParser();
        Object obj = parser.parse(new FileReader("your_file.side"));
        JSONObject jsonObject = (JSONObject) obj;
        JSONArray testsArray = (JSONArray) jsonObject.get("tests");

        for (Object testObj : testsArray) {
            JSONObject test = (JSONObject) testObj;
            String testName = (String) test.get("name");

            if (testName.equals(test_case_name)) {
                JSONArray commandsArray = (JSONArray) test.get("commands");

                for (Object commandObj : commandsArray) {
                    JSONObject command = (JSONObject) commandObj;
                    String target = (String) command.get("target");
                    System.out.println("command : " + command.get("command"));
                    System.out.println("target : " + target);
                }
            }
        }
    }
}
Nicoolasens
  • 2,871
  • 17
  • 22