Skip to content
This repository has been archived by the owner on Feb 18, 2021. It is now read-only.

Commit

Permalink
Start with a Google Search flow
Browse files Browse the repository at this point in the history
  • Loading branch information
akirk authored and hoverduck committed Jul 18, 2017
1 parent 0263bc9 commit 209599d
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
36 changes: 36 additions & 0 deletions lib/flows/google-flow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import webdriver from 'selenium-webdriver';
import fs from 'fs-extra';
import config from 'config';

import * as mediaHelper from '../media-helper.js';
import * as driverManager from '../driver-manager.js';
import * as dataHelper from '../data-helper.js';

import GoogleSearchPage from '../pages/google-search.js';

export default class GoogleFlow {
constructor( driver, screenSize ) {
this.driver = driver;

if ( screenSize === undefined ) {
this.screenSize = driverManager.currentScreenSize();
} else {
driverManager.resizeBrowser( driver, screenSize );
this.screenSize = screenSize;
}
}

search( query, culture ) {
var d = webdriver.promise.defer();
var driver = this.driver;
var screenSize = this.screenSize;
this.GoogleSearchPage = new GoogleSearchPage( driver, true, culture );
driver.sleep( 1000 );
driver.takeScreenshot().then( function( data ) {
mediaHelper.writeScreenshot( data, culture.toUpperCase() + '_' + screenSize + 'GOOGLE', true );
} );

d.fulfill( true );
return d.promise;
}
}
20 changes: 20 additions & 0 deletions lib/pages/google-search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var webdriver = require( 'selenium-webdriver' );
var by = webdriver.By;
var until = webdriver.until;
var config = require( 'config' );

function GoogleSearchPage( driver, visit, culture ) {
this.driver = driver;
this.explicitWaitMS = config.get( 'explicitWaitMS' );
this.expectedElementSelector = by.id( "com.google.ads.apps.anonymousapt.GwtModule" );
if ( visit === true ) {
if ( culture === undefined ) {
culture = "en";
}
var url = "https://adwords.google.com/apt/anon/AdPreview";
driver.get( url );
}
this.driver.wait( until.elementLocated( this.expectedElementSelector ), this.explicitWaitMS, 'Could not locate the Google Ad Preview IFrame. Check that is is displayed.' );
};

module.exports = GoogleSearchPage;
32 changes: 32 additions & 0 deletions specs-i18n/search-wordpress-on-google.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import test from 'selenium-webdriver/testing';
import config from 'config';

import * as driverManager from '../lib/driver-manager.js';

import GoogleFlow from '../lib/flows/google-flow.js';

const mochaTimeOut = config.get( 'mochaTimeoutMS' );
const startBrowserTimeoutMS = config.get( 'startBrowserTimeoutMS' );

const culture = process.env.CULTURE || 'en';

var driver;

test.before( function() {
this.timeout( startBrowserTimeoutMS );
driver = driverManager.startBrowser();
} );

test.describe( 'Search for WordPress on Google', function() {
this.timeout( mochaTimeOut );

test.beforeEach( function() {
driver.manage().deleteAllCookies();
driverManager.deleteLocalStorage( driver );
} );

test.it( `Can load Google`, function() {
const googleFlow = new GoogleFlow( driver, 'desktop' );
googleFlow.search( 'wordpress', culture );
} );
} );

0 comments on commit 209599d

Please sign in to comment.