URL comparator
URL Comparator
Pre-conditions:
baseUrlmust be set inkakunin.conf.jsthis.urlmust be set in page object available under the/pages/paththis.urlcan be set to relative path e.g./relative(in this case, the URL is built based onbaseUrlset inkakunin.conf.js)this.urlcan be set to alternative path e.g.https://new-page/absolute-url(in this case, the base URL is ignored)
For more examples, scroll to the bottom of the page. There's a table with examples.
// kakunin.conf.js
module.exports = {
baseUrl: 'https://example.com'
}
// /pages/example.js
const { BasePage } = require('kakunin');
class ExamplePage extends BasePage {
constructor() {
super();
this.url = '/relative'; // it gives 'https://example.com' + '/relative' (baseUrl + this.url)
}
}
// /pages/example-absolute.js
const { BasePage } = require('kakunin');
class ExampleAbsolutePage extends BasePage {
constructor() {
super();
this.url = 'https://example-absolute.com/absolute'; // it gives 'https://example-absolute.com/absolute' as the baseUrl is ignored
}
}
Wild cards
We added functionality that allows to parametrise the URLs. It's useful when the page url contains value that is dynamic e.g. URL with users details that includes ID.
So to make the Page Object which handles the validation on dynamic pages, you need to add a "wild card" to this.url.
To use "wild card" in Kakunin, you need to replace a dynamic part of URL like an ID with a value that start with :.
Every character between ":" sign and "/" will be ignored. In other, it does not matter if wild card is set to ":id" or ":something"!
Examples:
https://example-project/users/1001should be set tothis.url = https://example-project/users/:idhttps://example-project/users/1001/page/3should be set tothis.url = https://example-project/users/:id/page/:pageNumber
// /pages/example-users.js
const { BasePage } = require('kakunin');
class ExampleUsersPage extends BasePage {
constructor() {
super();
this.url = 'https://example-project/users/:id';
}
}
You can use as many wild card as you want in a URL.
Query params in URL
Another useful feature is functionality that allows to check query parameters in URL.
For example, if we got an URL https://example-query/resource?id=fb27c59e-2be6-446d-a5aa-1f6c32d31a68?id2=test.
It can be verified by setting this.url to a regex.
// /pages/example-query.js
const { BasePage } = require('kakunin');
class ExampleQueryPage extends BasePage {
constructor() {
super();
this.url = '/resource?id=[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}?id2=test';
}
}