How can I run an async function to prepare data that affects the url?
Great framework! Thank you so much for sharing it!
I am working on a project that has an ID in the URL.
Which means I need to create an entity and then get its ID to construct the URL.
How can I implement this in gemini?
In jasmine for example I can simply do that in beforeEach that supports async callbacks
So far I tried passing a function to setUrl but got an error that it has to be a string.
Also tried using nested suites with before but that doesn't seem to get me the required result too.
Hello. You are welcome.
Did I understand correctly that before run tests you know entire url?
For example you have one url - http://localhost/path?id=123 and another - http://localhost/path?id=456. You set in gemini config baseUrl = http://localhost.
And write test something like this:
[
'123',
'456'
].forEach((id) => {
gemini.suite(id, (suite) => {
suite
.setUrl(`/?id=${id}`)
.setCaptureElements('.some-elem')
.capture('plain');
});
})
Hi @DudaGod , what if the id is dynamic? For example I have hundreds of files, I don't want to maintain many tests which are identical apart from the URL and ID. I am using Node to scan directories, but want to then get and split the data into ID and URL like so:
// The test variable will be created dynamically
var tests = [
{name: 'first id', url: '/templates/contact-centre/contact-centre.html'},
{name: 'second id', url: '/templates/my-account/account-summary.html'}
];
// Then iterate through a test for each file.
for (var test of tests) {
gemini.suite(test.name, (suite) => {
suite
.setUrl(test.url)
.setCaptureElements('body')
.capture('plain')
}
}
@DudaGod I don't know the URL. I will know it after an async operation.
for example
BookStore.createBook().then( (book) => {
const url = `http://some.url/books/${book.id}`
....
})
Okay, why you can't do something like this:
BookStore.createBook().then((book) => {
const url = `http://some.url/books/${book.id}`;
gemini.suite(book.name, (suite) => {
suite
.setUrl(url)
.setCaptureElements('book')
.capture('plain');
});
})
This is more or less what I am doing now, but this does not work with grep and other features in Gemini.
Every time I run gemini, all the mock data is being prepared instead of a specific test.
I am encountering the same problem described above. I have a routine that builds the URL, which is called in my .before. The problem is that the .setUrl, which is the next statement in the chain, is executed before the routine called in my .before completes execution.
I also did exactly what DudaGod suggested and tried to put my suite in a then off my function call.
const uploadDoc = require('./uploadDoc');
const buildUserSession = require('./buildUserSession');
function getUrl(fileName) {
return new Promise(function(resolve, reject) {
uploadDoc(fileName)
.then(function(docId) {
buildUserSession(docId)
.then(function(url) {
console.log('URL: ' + url);
if (url.length > 0)
resolve(url);
else
reject("Url has 0 length");
});
});
})
}
getUrl('Event-Planner-Contract.docx')
.then((url) => {
gemini.suite('proof-of-concept', (suite) => {
suite
.setUrl(url)
.setCaptureElements('#element-to-capture')
.capture('plain');
})
});
This would be sufficient if I could get it to work. However, I get:
(node:13415) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): ReferenceError: gemini is not defined
Any ideas of assistance would be greatly appreciated.
let _gemini = gemini;
_gemini.suite("Folder name", async (suite) => {
let res = await axios.get("https://www.google.com");
other code