nightwatchjs / mobile-helper-tool

Easily setup all the requirements needed to get started with mobile-testing using Nightwatch.
https://nightwatch.org
3 stars 14 forks source link

Safari on ios simulator is not loading internal secure sites without warning #9

Open richardjimenez52 opened 1 year ago

richardjimenez52 commented 1 year ago

macbook m1 pro node v16.13.2 nightwatch v2.6.10 safari iphone8

Trying to run our tests against an internal secure (https) site on safari and I keep getting the warning that the connection is not private even though the site is secure and its on our network. Works as expected when running against desktop browsers but not IOS safari emulator. I can manually bypass it by clicking show details and continue to site but this flow interrupts my automation.

I have tried

Screen Shot 2023-01-13 at 12 39 24 PM

garg3133 commented 1 year ago

Hi, can you try to manually open the simulator by running command open -a simulator and then check if you are able to access this site on Safari browser? This warning usually appears when the SSL certificate of the website is not valid and clearing the browser cache might help. Also, incorrect time set on the clock can also be another reason for this warning. But this issue does not seem to be related to Nightwatch.

richardjimenez52 commented 1 year ago

i'm using acceptInsecureCerts: true in my nightwatch config but it does not seem to be able to bypass this warning.

garg3133 commented 1 year ago

Hi, as mentioned in this StackExchange answer, can you try to execute CertificateWarningController.visitInsecureWebsiteWithTemporaryBypass() as javascript and see if it works for you?

Before navigating to the website, write this step: browser.execute('CertificateWarningController.visitInsecureWebsiteWithTemporaryBypass()').

If the above doesn't work, try this one also: browser.execute('javascript:CertificateWarningController.visitInsecureWebsiteWithTemporaryBypass()').

garg3133 commented 1 year ago

Also, can you share your configuration where you are setting acceptInsecureCerts: true?

richardjimenez52 commented 1 year ago

I have tried both scripts and both failed with the following error Error while running .executeScript() protocol action: A JavaScript exception occured: Can't find variable: CertificateWarningController

I executed the script before navigating to the url in the beforeEach()

Also here is my configuration:

    'ios.simulator.safari': {
      launch_url: "https://dls-wc-ng-test-app.dls-doc-site.dlas1.ucloud.int/smoke",
      //launch_url: "http://localhost:4200/smoke",
      desiredCapabilities: {
        alwaysMatch: {
        //   acceptSsl: false,
           acceptInsecureCerts: true
        },
        browserName: 'safari',
        platformName: 'iOS',
        //platformVersion: '15.0',
        'safari:useSimulator': true,
        // change the deviceName, platformVersion accordingly to run tests on
        // Run command: `xcrun simctl list devices`
        // 'safari:platformVersion': '15.0',
        'safari:deviceName': 'iPhone 14'
      },

      webdriver: {
        start_process: true,
        server_path: '',
        cli_args: [
          // --verbose
        ]
      }
    },
garg3133 commented 1 year ago

Okay, can you try to put acceptInsecureCerts: true outside of alwaysMatch? Like below:

desiredCapabilities: {
  //  acceptSsl: false,
  acceptInsecureCerts: true,
  browserName: 'safari',
  platformName: 'iOS',
  // ...other capabilities
richardjimenez52 commented 1 year ago

I have tried placing it outside as well but it is not working either. nightwatch tries to load it and then says it is loaded and then proceeds with the execution of the tests but the site is never really loaded ever and every test fails. If i manually spin up the emulator and go to the page i get the warning but I am able to manually proceed to the page. In the video below you'll see the output of the tests saying it's "loading" and then says "loaded" even though the page never loaded. i navigate to my url in my beforeEach. This long load time only happens because safari on t he ios device is sayign the site is secure so it i attempting to load it. once the site is manually trusted it works as expected

https://user-images.githubusercontent.com/102810560/214654648-bf20161c-55fe-47de-bda8-ee9708454992.mov