Nightwatch and Appium

113 views
Skip to first unread message
Assigned to tnguy...@gmail.com by me

Tan

unread,
Dec 10, 2019, 7:47:30 PM12/10/19
to NightwatchJs
Hi all. I have been able to install appium and executed a test file from nightwatch runner. This is my test script

module.exports = {
  tags
: ['www', 'appiumTest'],


 
'Demo test Google': function (client) {
    client
     
.url('http://www.google.com')
     
.waitForElementVisible('body', 1000)
     
.assert.title('Google')
     
.pause(5000)
     
.assert.visible('input[type=text]')
     
.setValue('input[type=text]', 'Hello World')
     
.end();
 
}
};


I am testing in safari browser using the iphone simulator on mac. Seems like its working with safari being launched and opening google page. The verification on assert.title passes. the test would then fail when checking for the search field. Note that this selector works when running via nightwatch normally. However when I execute via appium selenium port it fails. When running in verbose this is the error I receive

  Testing if the page title equals "Google".
LOG    
Completed command title (10 ms)
LOG    
Completed command title (10 ms)
LOG    
Completed command pause (5003 ms)
INFO
Request: POST /wd/hub/session/05f64a04-c5a0-4578-b777-b5457bc0d023/element
 
- data:  {"using":"css selector","value":"input[type=text]"}
 
- headers:  {"Content-Type":"application/json; charset=utf-8","Content-Length":51}
ERROR
Response 500 POST /wd/hub/session/05f64a04-c5a0-4578-b777-b5457bc0d023/element (14ms) {
  status
: 7,
  value
: {
    message
: 'An element could not be located on the page using the given search parameters.'
 
},
  sessionId
: '05f64a04-c5a0-4578-b777-b5457bc0d023'
}
 
Testing if element <input[type=text]> is visible. Element could not be located.  - expected "true" but got: "null"
    at
Object.Demo test Google (/Users/thanh/Documents/development/whitespectre/www_lounge_workflows/tests/www/common/orders/appiumTest.spec.js:25:15)
    at processTicksAndRejections
(internal/process/task_queues.js:75:11)


ERROR
: Unable to locate element: "input[type=text]" using: css selector


I have also tried xpath by changing that line of code to the below and this is the error I get

.assert.visible('xpath', '//div[contains(@class, "FPdoLc tfB0Bf")]//input[contains(@class, "gNO89b")]')




  Testing if the page title equals "Google".
LOG    
Completed command title (11 ms)
LOG    
Completed command title (10 ms)
LOG    
Completed command pause (5001 ms)
INFO
Request: POST /wd/hub/session/d3f11c6f-a1d7-4336-a0f5-29448a83232e/element
 
- data:  {"using":"css selector","value":"xpath"}
 
- headers:  {"Content-Type":"application/json; charset=utf-8","Content-Length":40}
ERROR
Response 500 POST /wd/hub/session/d3f11c6f-a1d7-4336-a0f5-29448a83232e/element (15ms) {
  status
: 7,
  value
: {
    message
: 'An element could not be located on the page using the given search parameters.'
 
},
  sessionId
: 'd3f11c6f-a1d7-4336-a0f5-29448a83232e'
}
 
//div[contains(@class, "FPdoLc tfB0Bf")]//input[contains(@class, "gNO89b")]  - expected "true" but got: "null"
    at
Object.Demo test Google (/Users/thanh/Documents/development/whitespectre/www_lounge_workflows/tests/www/common/orders/appiumTest.spec.js:25:15)
    at processTicksAndRejections
(internal/process/task_queues.js:75:11)


ERROR
: Unable to locate element: "xpath" using: css selector



Note that the second try using xpath it is still trying to use css selector. Except this time it is taking "xpath" as the value instead of my actual xpath. 

I was wondering if anyone out there is running appium test via nightwatch at all that can help me go further? Or has no one tried this for a reason that it just does not work?

Any help is much appreciated


Dustin Ogan

unread,
Dec 11, 2019, 12:32:40 PM12/11/19
to nightw...@googlegroups.com
Can you try 
.waitForElementVisible('input[type=text]', 60000)

Mainly just want to rule out latency as the issue with a dynamic wait. If this passes and the time is longer than 5s you have your answer, albeit a weird latency problem with appium.   If it doesn't I can keep looking.  Doesn't' seem to be your syntax though, if it runs in standard nightwatch. 

--
You received this message because you are subscribed to the Google Groups "NightwatchJs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nightwatchjs...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nightwatchjs/74f57b9f-99a8-4cec-afe8-670a5b814ed2%40googlegroups.com.

Tan

unread,
Dec 11, 2019, 6:14:46 PM12/11/19
to NightwatchJs
Hi Dustin. Thanks for the reply. Its much appreciated. I went ahead and tried your suggestion. But looks like we get the same issue and its not found. 

Running:  Demo test Google
 
Element <body> was visible after 31 milliseconds.

 
Testing if the page title equals "Google".

 
Timed out while waiting for element <input[type=text]> to be present for 60000 milliseconds.  - expected "visible" but got: "not found"
    at
Object.Demo test Google (/Users/thanh/Documents/development/whitespectre/www_lounge_workflows/tests/www/common/orders/appiumTest.spec.js:25:8)

    at processTicksAndRejections
(internal/process/task_queues.js:75:11)


Not sure what else I can try. Do you have any other suggestions at all? Have you ever used a appium/nightwatch setup before? 
To unsubscribe from this group and stop receiving emails from it, send an email to nightw...@googlegroups.com.

Dustin Ogan

unread,
Dec 11, 2019, 7:25:01 PM12/11/19
to nightw...@googlegroups.com
I don't have appium, but i just found something interesting by switching user agent.   In the mobile version of google the type of the input is 'search' where as on the web page version it is type text

image.png

I'm wondering if this is contributing to your test failing , since that identifier wouldn't be found in this case.  

To unsubscribe from this group and stop receiving emails from it, send an email to nightwatchjs...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nightwatchjs/c5b4a2e0-afc5-452b-a091-bb73ddd88a8f%40googlegroups.com.

Tan

unread,
Dec 11, 2019, 7:48:07 PM12/11/19
to NightwatchJs
You are 100% correct. I was also speaking to a friend today. And he suggested I try and test on a different site. Because he has known google to have different elements between web and mobile. So since my last message to you, I tried to run a test on wikipedia instead. And guess what? It worked perfectly. So I then wrote a test file for the website that I test for work and so far so good. I am able to so far reuse the existing page objects which I already created for the desktop browser test and its great. Looking forward to exploring more with this set up. Very exciting indeed. Thanks again for your input on this. Your thoughts are much appreciated. But I think we can mark this one as solved now :) 

Prabhat Verma

unread,
Nov 11, 2020, 4:02:28 PM11/11/20
to NightwatchJs
Hi Tan,

Can anyone please share how your nightwatch.json or nightwatch.conf file looks like for running appium with nightwatch. I have a need where i need to test existing nightwatch tests on Mobile web.

Any help here is appreciated.

Thank You

Tan

unread,
Nov 11, 2020, 8:01:15 PM11/11/20
to NightwatchJs
Hi Prabhat. Unfortunately I am no longer working for that company that I was at when I was on this particular project. So this might be very outdated by now but I hope this helps you take this further. It was very exciting when I got this working and things were looking promising. So I hope this helps. Good luck

```
module.exports = {
  src_folders: ['tests'],
  live_output: false,
  output_folder: process.env.REPORTS_PATH || 'reports',
  custom_commands_path: [
    './custom_commands',
    './custom_commands/common',
    './custom_commands/admin',
    './custom_commands/www'
  ],
  page_objects_path: [
    './pages',
    './pages/admin',
    './pages/www',
    './pages/common'
  ],
  globals_path: './config/globals',

  test_settings: {
    default: {
      filter: '**/*.spec.js',
      exclude: '',
      selenium_host: 'localhost',
      selenium_port: 4444,
      desiredCapabilities: {
        browserName: 'chrome',
        javascriptEnabled: true,
        acceptSslCerts: true,
        chromeOptions: {
          prefs: {
            credentials_enable_service: false,
            download: {
              default_directory: process.cwd() + '/download_folder',
              prompt_for_download: false
            },
            profile: {
              password_manager_enabled: false,
              default_content_setting_values: { automatic_downloads: 1 }
            }
          }
        }
      },
      screenshots: {
        enabled: true,
        on_failure: true,
        on_error: false,
        path: `./${process.env.SCREENSHOTS_PATH || 'screenshots'}`
      }
    },

    ios: {
      filter: '**/*.spec.js',
      exclude: '',
      selenium_host: '127.0.0.1',
      selenium_port: 4723,
      desiredCapabilities: {
        browserName: 'Safari',
        platformName: 'iOS',
        platformVersion: '13.3',
        deviceName: 'iPhone 11 Pro Max'
      },
      selenium: {
        start_process: false,
        server_path: 'node_modules/selenium-standalone/bin/selenium-server-standalone-3.9.1.jar',
        log_path: '',
        host: 'localhost',
        port: 4724
      },
      screenshots: {
        enabled: true,
        on_failure: true,
        on_error: false,
        path: `./${process.env.SCREENSHOTS_PATH || 'screenshots'}`
      }
    },

    ci: {
      selenium_host: 'selenium',
      desiredCapabilities: {
        chromeOptions: {
          prefs: {
            download: {
              default_directory: '/tmp/download_folder'
            }
          }
        }
      }
    },

    parallel: {
      test_workers: {
        enabled: true,
        workers: 2
      }
    },

    ci_parallel: {
      selenium_host: 'selenium',
      desiredCapabilities: {
        chromeOptions: {
          prefs: {
            download: {
              default_directory: '/tmp/download_folder'
            }
          }
        }
      },
      test_workers: {
        enabled: true,
        workers: 2
      }
    }
  }
};
```

Reply all
Reply to author
Forward
0 new messages