So here is the process in words.
What I am doing right now is I have a try/except block to visit the url and have an assertion to expect the final page with the correct title, to check if any other thing happens prior to this I have a long timeout before . After the timeout expires, if the page is not the corrct one, it then proceeds to my exceptions, but my problem with this approach is that everytime something goes wrong, my code still has to wait for the entire duration of my timeout before realizing something went wrong. So here are my questions:
loop = False
while not loop:
context = await browser.new_context(proxy = {"server": f'http://{port}',"username":user,"password":pwd})
try:
await page.goto(f"http://specific url")
await expect(page).to_have_title("Final Prod"),timeout=timeout)
except Exception as e:
if "ERR_TIMED_OUT" in str(e) or "ERR_INVALID_AUTH_CREDENTIALS" in str(e) or "NS_ERROR_PROXY_CONNECTION_REFUSED" in str(e) or "NS_ERROR_NET_TIMEOUT" in str(e)\
or "NS_ERROR_CONNECTION_REFUSED" in str(e) or "NS_ERROR_FAILURE" in str(e) or "NS_ERROR_PROXY_CONNECTION_REFUSED" in str(e) or "NS_ERROR_FAILURE" in str(e)\
or "NS_ERROR_PROXY_BAD_GATEWAY" in str(e):
print(f"{str(e)}, trying new proxy. Bad proxy {proxy}")
try:
self.remove_bad_proxy(proxy)
except:
pass
proxy = random.choice(proxy_list)
port = f'{proxy.split(":")[0]}:{proxy.split(":")[1]}'
user = proxy.split(":")[2]
pwd = proxy.split(":")[3]
await context.close()
elif:
page_title = await page.title()
if page_title == "Loyalty" or page_title == "Problem loading page" or page_title == "Access Denied":
try:
self.remove_bad_proxy(proxy)
except:
pass
proxy = random.choice(proxy_list)
port = f'{proxy.split(":")[0]}:{proxy.split(":")[1]}'
user = proxy.split(":")[2]
pwd = proxy.split(":")[3]
await context.close()
else:
loop = True
This thread is trying to answer question "How can I quickly catch any of the possibilities mentioned without having to wait? How can I consolidate all the different proxy, network errors I keep getting so I can catch them all, versus what I am doing right now which is wait for a new error and add it to my exception block?"
Important caveats. Loading the final page may sometimes take 10-15 sec but all other errors (except for the stuck redirect) will happen almost immediately. So I would want to optimize my code so it recognizes any of the other outcomes right away and if no known error occurs then to wait the full length of my timeout to see if it simply got stuck on Title==Loyalty.
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].