A user should be able to generate gauge specifications along with implemented steps from a recorded taiko script.
When a user records a complete workflow it can turn into a gauge scenario.
Example:-
The following taiko script
await openBrowser();
await goto("google.com");
await write("taiko test automation");
await click("Google Search");
await closeBrowser();
can be converted into following
googleSearch.spec
# Specification
* open browser
## Scenario
* go to "google.com"
* write "taiko test automation"
* click "Google Search"
___
* close browser
and
googleSearchImplementation.js
step("open browser", async () => openBrowser());
step("go to <url>", async (url) => {
await goto(url);
});
step("write <query>", async (query) => {
await write(query);
})
step("click <link>", async (link) => {
await click(link)
});
step("close browser", async () => closeBrowser());
The decided solution is to generate the code from taiko
taiko REPL (let's say .gauge).gauge command.gauge command it will show the generated specification and implementations on the console.How about recording will be converted to one method instead of one for each line.
With ability to load a script before recording https://github.com/getgauge/taiko/issues/272. One can record a logical chunk at a time. A scenario has many logical chunks.
Example - booking a movie ticket
movie.js then selecting gold/executive seats are 2 separate logical chunks. Both can be recorded after playing back movie.js. movie.js, goldseat.js, executiveseat.js payment.js are generated by taiko all can be converted to gauge steps for movieselection, seatselection,paymentoption... which user can work with and continue to refactor.With this one can avoid generating code for duplicate steps as well. As the user can load a recorded script to avoid re-recording steps.
Thoughts?
@sguptatw This make sense.
openBrowser and closeBrowser if the given path belongs to a gauge projectopenBrowser and closeBrowser as beforeScenario and afterSceanrio if project is not gauge project (after creating a new project).Please add your thoughts.
Here's what I think works best.
$ taiko
> openBrowser()
> goto("google.com")
> write("Gauge test automation")
> click("google search")
> closeBrowser()
> .step
step("<insert step name>", async () => {
goto("google.com");
write("Gauge test automation")
press("Enter")
});
This is for copying it to a step implementation file or previewing the step. Note, that Taiko does not ask for the step name, use a place holder instead.
To save it to an external file
> .step tests/google.js
If the file does not exist generate the following.
/* globals gauge*/
"use strict";
const { openBrowser,write, closeBrowser, goto, press, text, contains } = require('taiko');
beforeSuite(async () => openBrowser());
afterSuite(async () => closeBrowser());
step("<insert step name>", async () => {
goto("google.com");
write("Gauge test automation")
press("Enter")
});
If a file is already there, with steps, append to it. For e.g.
/* globals gauge*/
"use strict";
const { openBrowser,write, closeBrowser, goto, press, text, contains } = require('taiko');
beforeSuite(async () => openBrowser({ headless: headless }));
afterSuite(async () => closeBrowser());
step("Pre existing step", async () => {
goto('foo');
click('bar');
});
step("<insert step name>", async () => {
goto("google.com");
write("Gauge test automation")
press("Enter")
});
Other points.
.step will not create a spec file.step will not initialize a gauge project.Initializing a gauge project etc needs to be done outside taiko. Or on a separate command.
Questions
"<insert step text here>" in the specification it is getting auto-completed as a step with only a static parameter..step are recorded for the same project and code is added to gauge project, multiple hooks with open and closeBrowser are generated. Should the code generation for the hook be separated like/*hook to open and close browser. Do not add this if it already exists*/
"use strict";
const { openBrowser, closeBrowser } = require('taiko');
beforeSuite(async () => openBrowser());
afterSuite(async () => closeBrowser());
/* globals gauge*/
"use strict";
const { write, goto, press, text, contains } = require('taiko');
step("insert step name", async () => {
goto("google.com");
write("Gauge test automation")
press("Enter")
});
@sguptatw
<insert step text here> as the text, it could be a comment, and the step text can be either an empty string or no value. No value will cause a syntax error.Something like this:
// Insert step text below as first parameter
step("", async () => {
// generated code
})
openBrowser etc calls is better than duplicating it.A step is generated for a gauge project. A project initialized with the template(the default is taiko template) already has the hook with openBrowser and closeBrowser. So on second thoughts I think we need not generate the hook details at all. Thoughts?
As the openBrowser and closeBrowser happens in the beforeSuite and afterSuite .step must not generate hook code as it will be initialized during gauge init js
The required changes has been made and should be available in https://github.com/getgauge/taiko/commit/06bd1cd297ae27034f51f1c566202a563e3259de .
Most helpful comment
Other points.
.stepwill not create a spec file.stepwill not initialize a gauge project.Initializing a gauge project etc needs to be done outside taiko. Or on a separate command.