Files
openobserve/tests/ui-testing/pages/createOrgPage.js
T
Shyam Panjiyarandhengfei yang 4081b3959f test: users and organizations playwright (#7104)
### **User description**
users and organizations test cases


___

### **PR Type**
Tests, Enhancement


___

### **Description**
- Introduce `UserPage` page object for IAM flows

- Add interactive CRUD operations for users

- Implement Playwright tests for user scenarios
  - errors, creation, duplicate, cancel, delete, update


___



### **Changes walkthrough** 📝
<table><thead><tr><th></th><th align="left">Relevant
files</th></tr></thead><tbody><tr><td><strong>Enhancement</strong></td><td><table>
<tr>
  <td>
    <details>
<summary><strong>userPage.js</strong><dd><code>Add UserPage interactions
and locators</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; </dd></summary>
<hr>

tests/ui-testing/pages/userPage.js

<li>Introduces <code>UserPage</code> class for IAM navigation<br> <li>
Adds form interaction and CRUD methods<br> <li> Defines selectors for
user fields and buttons<br> <li> Includes alerts and existence
verification methods


</details>


  </td>
<td><a
href="https://github.com/openobserve/openobserve/pull/7104/files#diff-6436e468818bd5517200c83a5bbe6edf60da28e81f53a73b8aa9d57eaf20c2e6">+129/-0</a>&nbsp;
</td>

</tr>
</table></td></tr><tr><td><strong>Tests</strong></td><td><table>
<tr>
  <td>
    <details>
<summary><strong>usersOrg.spec.js</strong><dd><code>Add users and org
Playwright tests</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
<hr>

tests/ui-testing/playwright-tests/usersOrg.spec.js

<li>Adds <code>Users and Organizations</code> test suite<br> <li> Covers
email/role validation and error messages<br> <li> Tests user creation,
duplicates, cancel flows<br> <li> Includes delete and update test
scenarios


</details>


  </td>
<td><a
href="https://github.com/openobserve/openobserve/pull/7104/files#diff-01a0201901f4022cf6708a20432f8a70bc20ac5ccdb9943fd5a6b41eaf0e550b">+213/-0</a>&nbsp;
</td>

</tr>
</table></td></tr></tr></tbody></table>

___

> <details> <summary> Need help?</summary><li>Type <code>/help how to
...</code> in the comments thread for any questions about PR-Agent
usage.</li><li>Check out the <a
href="https://qodo-merge-docs.qodo.ai/usage-guide/">documentation</a>
for more information.</li></details>

---------

Co-authored-by: hengfei yang <hengfei.yang@gmail.com>
2025-06-11 13:08:41 +08:00

117 lines
3.8 KiB
JavaScript

export class CreateOrgPage {
constructor(page) {
this.page = page;
}
async createOrg(newOrgName) {
const basicAuthCredentials = Buffer.from(`${process.env["ZO_ROOT_USER_EMAIL"]}:${process.env["ZO_ROOT_USER_PASSWORD"]}`).toString('base64');
const headers = {
"Authorization": `Basic ${basicAuthCredentials}`,
"Content-Type": "application/json",
};
let newOrgBody = {
"name": newOrgName,
}
const fetchResponse = await fetch(
`${process.env.INGESTION_URL}/api/organizations`,
{
method: "POST",
headers: headers,
body: JSON.stringify(newOrgBody),
}
);
try {
const response = await fetchResponse;
const contentType = response.headers.get("content-type");
if (contentType && contentType.includes("application/json")) {
const jsonData = await response.json();
console.log(response.status);
console.log(jsonData);
return jsonData.identifier;
// Process JSON data here
} else {
const textData = await response.text();
console.log("Response is not JSON:", textData);
return textData;
// Handle the non-JSON response here
}
} catch (error) {
console.error("Failed to parse JSON response:", error);
return "";
}
}
async navigateToOrg() {
await this.page.locator('[data-test="menu-link-\\/iam-item"]').click();
await this.page.locator('[data-test="iam-organizations-tab"]').click();
}
async clickAddOrg() {
await this.page.locator('[data-test="Add Organization"]').click();
}
async fillOrgName(orgName) {
await this.page.locator('[data-test="org-name"]').fill(orgName);
}
async clickSaveOrg() {
await this.page.locator('[data-test="add-org"]').click();
}
async checkSaveEnabled() {
const saveButton = this.page.locator('[data-test="add-org"]');
// Check if the button is enabled
const isEnabled = await saveButton.isEnabled();
if (!isEnabled) {
console.error('The "Add Organization" button is not enabled.');
return false; // Return false to indicate the button is not enabled
}
return true; // Return true if the button is enabled
}
async clickCancelButton() {
const cancelButton = this.page.locator('[data-test="cancel-organizations-modal"]');
// Check if the button is visible and enabled before clicking
const isVisible = await cancelButton.isVisible();
const isEnabled = await cancelButton.isEnabled();
if (isVisible && isEnabled) {
await cancelButton.click();
} else {
console.error('The "Cancel" button is not visible or enabled.');
throw new Error('Attempted to click "Cancel" button, but it is not visible or enabled.');
}
}
async searchOrg(orgName) {
await this.page.getByPlaceholder('Search Organization').click();
await this.page.getByPlaceholder('Search Organization').fill(orgName);
await this.page.waitForTimeout(5000);
}
async verifyOrgNotExists(expect) {
const mainSection = this.page.locator('[data-test="iam-page"]').getByRole('main');
const textContent = await mainSection.textContent();
console.log('Main section text:', textContent); // Debugging line
await expect(mainSection).toContainText('No data available');
}
async verifyOrgExists(orgName) {
await expect(this.page.locator('tbody')).toContainText(orgName);
}
}