Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/isomorphic/locatorGenerators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ function combineTokens(factory: LocatorFactory, tokens: string[][], maxOutputSiz

function detectExact(text: string): { exact?: boolean, text: string | RegExp } {
let exact = false;
const match = text.match(/^\/(.*)\/([igm]*)$/);
const match = text.match(/^\/(.*)\/([dgimsuvy]*)$/);
if (match)
return { text: new RegExp(match[1], match[2]) };
if (text.endsWith('"')) {
Expand Down
9 changes: 9 additions & 0 deletions tests/library/locator-generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,15 @@ it('reverse engineer locators', async ({ page }) => {
javascript: 'getByLabel(/Last\\s+name/i)',
python: 'get_by_label(re.compile(r"Last\\s+name", re.IGNORECASE))',
});
// Only JavaScript can express these flags, other languages drop them.
for (const flags of ['u', 's', 'y', 'd', 'v', 'gm']) {
for (const [engine, method] of [['text', 'getByText'], ['label', 'getByLabel']]) {
const selector = `internal:${engine}=/Hello/${flags}`;
const locatorString = asLocator('javascript', selector);
expect.soft(locatorString, selector).toBe(`${method}(/Hello/${flags})`);
expect.soft(parseLocator('javascript', locatorString, 'data-testid'), selector).toBe(selector);
}
}

expect.soft(generate(page.getByPlaceholder('hello'))).toEqual({
csharp: 'GetByPlaceholder("hello")',
Expand Down
Loading