<repo_name>praveenprasannan/webdriverio-yarn-demo<file_sep>/pages/GoogleHomePage.js
import Page from './Page';
import constants from '../shared/constants';

class GoogleHomePage extends Page {
  // Page elements
  static get searchBox() {
    return browser.element('#tsf > div:nth-child(2) > div > div.RNNXgb > div > div.a4bIc > input');
  }

  static get searchButton() {
    return browser.element('#tsf > div:nth-child(2) > div > div.FPdoLc.VlcLAe > center > input[type="submit"]:nth-child(1)');
  }

  // Actions
  static setSearchKey(value) {
    return this.searchBox.setValue(value);
  }

  static clickOnSearch() {
    return this.searchButton.click();
  }

  // Helper Methods
  static doGoogleSearch(value) {
    this.setSearchKey(value);
    this.clickOnSearch();

    return browser.waitUntil(() => this.title().includes(value), constants.BROWSER_WAIT, 'expected the search results page which contains the searched value within wait period');
  }
}

export default GoogleHomePage;
<file_sep>/tests/australia_test.js
import { expect } from 'chai';
import HomePage from '../pages/AustraliaHomePage';
import constant from '../shared/constants';

describe('Australian Government Tests', () => {
  it('should open the Aus Govt homepage with the expected title', () => {
    HomePage.openUrl(constant.AU_HOMEPAGE);
    expect(HomePage.title()).to.equal('australia.gov.au');
  });

  it('should open myGov login page', () => {
    HomePage.clickOnMyGov();
    expect(HomePage.title()).to.equal('Sign-in - myGov');
  });
});
<file_sep>/shared/constants.js
const constants = {
  BROWSER_WAIT: 3000,
  AU_HOMEPAGE: 'http://australia.gov.au/'
};

export default constants;
<file_sep>/README.md
# WebdriverIO demo using Yarn

Uses http://webdriver.io to execute selenium web tests. Tests can be run locally using the wdio.conf.js config file, which uses chromedriver to execute browser tests.

### Environment Setup

#### 1. Global Dependencies
  * Install [Node.js](https://nodejs.org/en/)
  ```
  $ brew install node
  ```
  * Install [Yarn](https://yarnpkg.com/lang/en/docs/install/)
  ```
  $ brew install yarn
  ```

#### 2. Project Dependencies

* Install Node modules
```
$ yarn install
```

### Running Tests

* To run tests (for the test suite)
```
$ yarn test
```

* Run a single test (if you use the same folder structure)
```
$ yarn test --spec tests/folder/filename.js
```

### Docs & further reading

* http://webdriver.io
* http://webdriver.io/guide/usage/selectors.html
* http://blog.kevinlamping.com/selecting-elements-in-webdriverio
<file_sep>/tests/google_test.js
import { expect } from 'chai';
import HomePage from '../pages/GoogleHomePage';

describe('Google Tests', () => {
  it('should open the Google homepage with the expected title', () => {
    HomePage.open();
    expect(HomePage.title()).to.equal('Google');
  });

  it('should do a search to get results', () => {
    HomePage.doGoogleSearch('sydney');
    expect(HomePage.title()).to.equal('sydney - Google Search');
  });
});
