Not able to locate html tags in spectron test


#1

Posted this question here: http://stackoverflow.com/questions/40890232/not-able-to-locate-html-tags-in-spectron-test

I have a very simple index.html in an electron app:

<!DOCTYPE html>
<html>
  <head>
    <title>the title</title>
  </head>
  <body>
    haha
  </body>
</html>

Here is the spectron test (using jest):

it('should have the right controls', function() {
    return app.client.browserWindow.isVisible()
        .then(() => {
            return app.client.browserWindow.getTitle().then(text => expect(text).toBe('the title'));
        }).then(() => {
            return app.browserWindow.getTitle().then(text => expect(text).toBe('the title'));
        }).then(() => {
            return app.client.getText('body').then(text => expect(text).toBe('haha'));
        });
});

But app.client.getText doesn’t seem to work properly. Here is the error I get:

expect(received).toBe(expected)

Expected value to be (using ===):
  "haha"
Received:
  "1
<!DOCTYPE html>
2
<html>
3
<head>
7
    haha
8
</body>
9
</html>
Pause On Caught Exceptions
Call Stack
Not Paused
Breakpoints
No Breakpoints
DOM Breakpoints
XHR Breakpoints
Event Listener Breakpoints
Event Listeners
Not Paused"

It looks like the whole index.html doc is being returned as a (processed) string instead of just the body tag.

What is the correct way to check the html tags?

Many thanks!


#2

OK, found the culprit. I had the devtools enabled in main.js: mainWindow.webContents.openDevTools(), and this was disrupting spectron tests.