Automate captcha on signup page

please suggest me the best way to automate captcha in cypress automation tool. I am able to click on that checkbox but then the image is opened that needs to be manually done. is there any way to bypass totally recaptcha .

Now I am trying to click on green checkmark button at the bottom in the image. but it is giving me timeout error

mu code is
cy.get(’[style=“z-index: 2000000000; position: relative; width: 400px; height: 580px;”] > iframe’).then(($iFrameContent1) => {

  cy.wait(5000)

  const $body = $iFrameContent1.contents().find('body')

  cy.wait(5000)

  cy.wrap($body).find('[title="Solve the challenge"]').click();

  cy.wait(5000)

Hi @satveerqa​:sunglasses::sunglasses:
What you are trying to do is not that easy. The point of captcha is that it cannot be bypassed by bots. As your automated test is nothing else, but a bot, you should not be able to fully automate the captcha.
One solution though to handle this problem is to disable the captcha service in test environment and activate it in production.

Maybe some people here - who are more experienced in automation than me found other alternatives😉

3 Likes

This is Selenium, but the principle would be the same in Cypress:

2 Likes

Useful article. My preference would definitely be the semi automated approach, rather than temporarily breaking security, since it does actually mean the test is fully end to end. Obviously a none starter if you have a large, frequent overnight build and test.

1 Like

Thank you very much @baysha . I saw your post that looks useful for me. I am already able to click on the checkbox then image screen appears that is under the frame. I installed buster captcha extension in my chrome browser and Now I need to click on the that green checkmark under that frame. when execution reached there it gives mere error timeout exception error.

cy.wait(5000)

const $body = $iFrameContent1.contents().find(‘body’)

cy.wait(5000)

cy.wrap($body).find(’[title=“Solve the challenge”]’).click();

cy.wait(5000)

Thanks for your response. but we cannot disable it from test environment. because our QA env is same like production environment.

2 Likes

Disable it on the test environment :stuck_out_tongue:

2 Likes

Yeah, basically I have lost so much sleep over this kind of test step which is not a test step. (What’s really happening here in a distorted version of reality, is that you end up testing a 3rd party component but because you are not paying for the 3rd party component testing it is moot to do so.)

Testing the Captcha enforcement is something altogether different and separate, and does not require solving them. Captchas appear when the server is not trusting your IP, so having the server whitelist you will be one way of fixing this in production and in test - while still letting testers test that it is working. That may not work in some cases. but basically unless the test is supposed to test the 3rd part component, don’t do it. Get your devs to give you a bypass of some sort, this will otherwise suck up time better spent detecting product bugs in your product code not in freebie code.

1 Like

how to resolve this erorr AssertionError

Timed out retrying after 4000ms: Expected to find element: [title="Solve the challenge"] , but never found it.

1 Like

Agree, it’s not easy to push back @satveerqa . At some point, identical environments are not useful, test automation is very often imperfect in itself, for example if you have just installed a browser plugin or any component to work around an “automation” issue, it taints the environment and the test, since the test “jig” (it no longer a normal browser) gradually represents less of the customer typical equipment over time. I would not want to be setting up my entire browser farm of machines with a plugin that may expire at any time, and end up messing you about on a unlucky day in the future. My guess, is it will work for a year or two, which might be enough time, always be tactical. You will want to bring this issue up in the next team retrospective even if this does work around, as it adds risk.

1 Like

Yes I know identical env are not useful at all, but In case when we have some issue on production then we needs to verify the same thing on QA. then we need both environments same.

I am very close to the solution the only thing is to click on that green icon that is under frame.
I gave the code to identify frame first and then click on that icon under the frame.

2 Likes

Everything costs, and being a tester means you have to choose. It’s still “good” to have identical environments, but not everyone can afford 3 environments. Good to see you are winning with this test case though. Everyone has their own context, and I hope our encouragement helps you to explain to and get more help from your team with some of the pains.

Thanks for your reply. Yup I am just not sure about my code is correct or needs to be improve. because the error says timeout unable to find that element.

is there any way I can add wait in my code so it will keep looking that element and wont fail for some time constraint

it fails here

//cy.wrap($body).find(’ #solver-button’).should(‘be.visible’).click();

1 Like

Some types of captcha are assessing user behavior before the click - how you move the mouse etc. Or even analyse the browser cookies as evidence of your previous human-like behavior. That’s why they’re effectively impossible to automate. I can’t say whether this applies to your captcha but it seems likely to me.

2 Likes

As for solving the captcha, if I was forced to, I would use a plugin like you are doing.

For intermittent failures I can give this tip.
In my test framework we always take a screenshot, I know cypress has a “movie” mode that will take a video, I’ve never used cypress but I know it can do that. Adapt your test F/W so that it takes a movie and or screenshot and saves it, if the test PASSES, then remember to delete the video or screenshot file since that will save you tonnes of space and prevent other nightmares. Another thing to do is to dump out either the entire DOM when a test fails or to dump out interesting parts of the DOM in the test log. Test automation frameworks are a lot of work and humps like this captcha force you to build out your tooling quite a bit.

I’m tempted to hack that Runescape voting captcha now.