Puppeteerでspanタグのテキストを確認する

f:id:hawaiiantime:20190219114814p:plain

毎回ビルド時に、ランダムなポストフィックスがクラス名につくので、正規表現で指定する。

const spanTitle = await page.waitForSelector('span[class^="foo_title-text"]', { visible: true });
const title = await (await spanTitle.getProperty("textContent")).jsonValue();
expect(title).toBe("パンプキンアイスクリーム");

参考
CSSを正規表現で適用先を絞り込む