Skip to content

Commit 88c0b24

Browse files
committed
Remove XPath selector and use other selectors like ID, CSS
for Testing Helix-UI
1 parent ed1c68d commit 88c0b24

File tree

3 files changed

+21
-28
lines changed

3 files changed

+21
-28
lines changed

test/behavioral/behavioral.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,17 @@ export function suite(browserName: string) {
3131
});
3232

3333
test("nav/guides", async testExecutionObject => {
34-
await util.$x(driver, "//nav//hx-disclosure", "Guides").click();
35-
let guidesText = await driver.findElement(By.id("nav-Guides")).getText();
36-
testExecutionObject.deepEqual(guidesText, "Getting Started");
34+
const expected = [
35+
"Getting Started",
36+
"FAQ",
37+
"React Compatibility",
38+
"Polyfills"
39+
];
40+
await driver.findElement(By.css("hx-disclosure")).click();
41+
const reveal = await driver.findElement(By.id("nav-Guides"));
42+
const links = await reveal.findElements(By.tagName('a'));
43+
const text = await util.getElementsText(links);
44+
testExecutionObject.deepEqual(text, expected);
3745
});
3846

3947
/**
@@ -44,15 +52,15 @@ export function suite(browserName: string) {
4452
if (browserName === "chrome") {
4553
test("tabs/first", async testExecutionObject => {
4654
await util.go(driver, "components/tabs");
47-
await tabTest(testExecutionObject, snappit, driver, "Cupcake Ipsum");
55+
await tabTest(testExecutionObject, driver, "android-desserts-tab-0", "Cupcake Ipsum");
4856
});
4957

5058
test("tabs/second", async testExecutionObject => {
51-
await tabTest(testExecutionObject, snappit, driver, "Biscuit Marshmallow");
59+
await tabTest(testExecutionObject, driver, "marshmallow", "Biscuit Marshmallow");
5260
});
5361

5462
test("tabs/third", async testExecutionObject => {
55-
await tabTest(testExecutionObject, snappit, driver, "Caramels Marzipan");
63+
await tabTest(testExecutionObject, driver, "android-desserts-tab-2", "Caramels Marzipan");
5664
});
5765
}
5866

test/behavioral/tests/tabs.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import {Snappit, WebDriver, Key} from "snappit-visual-regression";
1+
import {WebDriver, By, Key} from "snappit-visual-regression";
22
import {test, TestContext} from "ava";
33
import * as util from "../../common/util";
44

55
const getTab = async (
66
driver: WebDriver,
7-
tabName: string
7+
tabID: string
88
) => {
9-
const tab = await util.$x(driver, util.selectors.tab, tabName);
10-
return tab;
9+
const element = await driver.findElement(By.id(tabID));
10+
return element;
1111
}
1212

1313
const cycleLeft = async (driver: WebDriver) => {
@@ -24,11 +24,11 @@ const cycleRight = async (driver: WebDriver) => {
2424

2525
export default async (
2626
t: TestContext,
27-
snappit: Snappit,
2827
driver: WebDriver,
28+
tabID: string,
2929
tabName: string
3030
) => {
31-
const tab = await getTab(driver, tabName);
31+
const tab = await getTab(driver, tabID);
3232
await tab.click();
3333
t.is(await tab.getText(), tabName);
3434
await cycleLeft(driver);

test/common/util.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,6 @@ export async function snapshot(t: TestContext, element: WebElement) {
2828
t.snapshot(await element.getAttribute("outerHTML"));
2929
}
3030

31-
export function $x(
32-
driver: WebDriver,
33-
xpath: string,
34-
byText = "",
35-
) {
36-
if (byText.length) {
37-
xpath += `[contains(text(), '${byText}')]`;
38-
}
39-
40-
return driver.findElement(By.xpath(xpath));
41-
}
42-
4331
export async function getElementsText(
4432
elements: WebElement[]
4533
) {
@@ -57,9 +45,6 @@ export async function getElementsText(
5745
* Once that happens, pull this out of `util.ts` and move it someplace more page-object-y.
5846
*/
5947
export var selectors = {
60-
nav: "#stage > #nav",
61-
components: "#stage",
62-
tab: "//hx-tablist/hx-tab",
63-
domDiff: "*[data-dom-diff]",
48+
domDiff: "*[data-dom-diff]"
6449
}
6550

0 commit comments

Comments
 (0)