I’m looking into adding some e2e tests for our Confluence Cloud addon. I cannot find any official guideline,. tips or tools to do it.
I’m curious on what people have done to solve this issue. Do people use tools like puppeteer and run against dev instances? Create mocks that imitates Confluence behavior?
Do you know if it is documented somewhere? Or may you have some examples or skeleton?
I always have some basic errors while opening the home page. I am using the tokenAPI, but I think I am missing something.
Also, additional question, why did you choose WebDriverIO over Selenium?
Regards
Laurent
In the end a lot of test frameworks are just abstraction layers. Webdriver.io can use both Selenium WebDriver protocol as wel as Puppeteer. They expose an API that felt easy to use, but there are lot of other frameworks available with other APIs that might fit better for you.
Given that e2e testing is not specific to Atlassian, there is no official documentation about it. What kind of pointers are you looking for?
Euh yeah… well… we just log in with username/password
It’s difficult for me to share code as we have extended the browser with custom commands, but here is the logic for logging in. If you want to use it you will have to rewrite it to use default browser commands
export const loginToConfluence = async (username?: string, password?: string): Promise<void> => {
const isLoggedIn = await browser.exists('#com-atlassian-confluence', false);
if (!isLoggedIn && username && password) {
await browser.setValue('#username', username);
await browser.click('#login-submit', '#password');
await browser.setValue('#password', password);
await browser.click('#login-submit', '#com-atlassian-confluence');
} else {
return Promise.reject('Could not log in to Confluence, as the instance is not publicly avaiable and no credentials have been provided');
}
}
So, for posterity, this works with API token, BUT it does not handle well iframes.
If you use iframes, you need to use real login (with /wiki/login.action and fill the form)
Note: to use firefox with API token, you need to use a Proxy (see BrowserMobProxyServer examples)
private ChromeDriver getChromeDriver() {
WebDriverManager.chromedriver().setup();
ChromeOptions options = new ChromeOptions();
options.setLogLevel(ChromeDriverLogLevel.WARNING);
options.setHeadless(false); // or true if you want to hide browser
ChromeDriver driver = new ChromeDriver(options);
driver.setLogLevel(Level.WARNING);
DevTools devTools = driver.getDevTools();
devTools.createSession();
devTools.send(Network.enable(Optional.of(1000000), Optional.of(1000000), Optional.of(1000000)));
String token = "myemail:myapitoken";
String encodedToken = Base64.getEncoder().encodeToString(token.getBytes(StandardCharsets.UTF_8));
Map<String, Object> headers = Map.of("Authorization", "Basic " + encodedToken);
devTools.send(Network.setExtraHTTPHeaders(new Headers(headers)));
return driver;
}
private WebDriverWait getWaitDriver(RemoteWebDriver driver) {
return new WebDriverWait(driver, Duration.ofSeconds(30), Duration.ofSeconds(1));
}
@Test
void goToPage() {
RemoteWebDriver driver = getChromeDriver();
WebDriverWait wait = getWaitDriver(driver);
driver.get("https://laurent-ry.atlassian.net/wiki");
String pageTitle = driver.getTitle();
// Click on a page in the side bar
List<WebElement> elements = driver.findElements(By.xpath("//a[@aria-label='one page']"));
WebElement webElement = elements.get(0);
webElement.click();
wait.until(webDriver -> webDriver.getTitle().equals("one page - PERF - Confluence"));
pageTitle = driver.getTitle();
}