Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eg: skip if "This product is currently unavailable in your region" #48

Merged
merged 2 commits into from
Jan 23, 2023

Conversation

vogler
Copy link
Owner

@vogler vogler commented Jan 19, 2023

Skip games that are "currently unavailable in your region".
Fixes #46.

@vogler vogler changed the title fix for #46: "This product is currently unavailable in your region" eg: skip if "This product is currently unavailable in your region" Jan 19, 2023
@vogler vogler added store: epic-games feature New feature or request labels Jan 19, 2023
@SteveImmanuel
Copy link

This will produce the following error:

  waiting for frameLocator('#webPurchaseContainer iframe')
  locator resolved to visible <iframe class="" src="/purchase?highlightColor=0078f2&of…></iframe>
  Error: strict mode violation: locator(':has-text("unavailable in your region")') resolved to 8 elements:
    1) <html lang="en" class="no-js">…</html> aka locator('html')
    2) <body>…</body> aka locator('body')
    3) <div id="purchaseAppContainer" class="purchase-app-co…>…</div> aka locator('#purchaseAppContainer')
    4) <div id="purchase-page" class="purchase-page page-con…>…</div> aka getByText('× Loading your order... × Sorry, we\'re having trouble loading this page. Please ')
    5) <div id="purchase-app" class="purchase-app fade-in">…</div> aka locator('#purchase-app')
    6) <div class="payment-blocked">…</div> aka locator('div').filter({ hasText: 'This product is currently unavailable in your region.' }).nth(3)
    7) <div class="payment-blocked__container">…</div> aka locator('div').filter({ hasText: 'This product is currently unavailable in your region.' }).nth(4)
    8) <h2 class="payment-blocked__msg">This product is currently unavailable in your reg…</h2> aka getByRole('heading', { name: 'This product is currently unavailable in your region.' })

because the locator will match every element (from parent to child) that contains the string unavailable in your region as mentioned in the docs (https://playwright.dev/docs/other-locators#css-matching-by-text).

I tinkered a little bit and confirmed the following code works for this scenario,

...
      if (await Promise.any([
        iframe.locator('button:has-text("Place Order")').click(),
        iframe.locator(':has-text("unavailable in your region")').count().then((res) => res),
      ]) > 0) { // can't continue loop from the promise
        console.error('  This product is unavailable in your region!');
        continue;
      };
...

Also If I may ask, what does the iframe.locator('button:has-text("Place Order")').click() in the if statement returns if the promise is accepted, i.e., why do you need it inside the if statement?

@vogler
Copy link
Owner Author

vogler commented Jan 19, 2023

Thanks!
The problem with count is that it doesn't wait, so it may lead to a race if the element is loaded instead of already being there. But apparently waiting for the iframe before is enough as a barrier.
Since I didn't know, I waited for both alternatives and then checked afterwards if the 'unavailable' Promise won.
click's return type is Promise<void>, i.e., undefined as a value if fulfilled.

I simplified it and pulled up the check for count.

@vogler vogler merged commit 7196a26 into main Jan 23, 2023
@vogler vogler deleted the eg-unavailable-region branch January 23, 2023 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request store: epic-games
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unhandled "This product is currently unavailable in your region"
2 participants