galenframework / galen

Layout and functional testing framework for websites
http://galenframework.com
1.41k stars 161 forks source link

Galen Spec generator help #630

Open deepakkp opened 4 years ago

deepakkp commented 4 years ago

Hi team, please let us know how to generate spec files. we want to include commands in batch file and generate it or any particular spec generator method. please share the proper steps. i have tried below steps.but no luck.

http://galenframework.com/docs/reference-working-in-command-line/#SpecGenerator

javdeeva commented 4 years ago

I can share examples on Java what we implemented for our project. Galen test run is based on Selenium (Junit)

public static void generatePageDump(WebDriver driver, String pageName, String specPath) {
    try {
      new GalenPageDump(pageName).dumpPage(driver, SPEC_COMMON_PATH + specPath,
          DUMP_PATH);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
public static void generateSpecByPageDump(String specPath) {
    SpecGenerator generator = new SpecGenerator();
    SpecGeneratorOptions specGeneratorOptions = new SpecGeneratorOptions();
    specGeneratorOptions.setUseGalenExtras(true);

    try (InputStream inputStream =
             new FileInputStream(DUMP_PATH + "/page.json");
         OutputStream outputStream =
             new FileOutputStream(SPEC_COMMON_PATH + specPath, true)) {

      PageSpecGenerationResult pageSpecGenerationResult = generator.generate(inputStream, specGeneratorOptions);
      String spec = generator.generatePageSpec(pageSpecGenerationResult, specGeneratorOptions);

      outputStream.write(spec.getBytes());

    } catch (IOException e) {
      e.printStackTrace();
    }
  }