/
google-ad-preview-tool.js
57 lines (51 loc) · 1.28 KB
/
google-ad-preview-tool.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
* External dependencies
*/
import { By as by, until } from 'selenium-webdriver';
/**
* Internal dependencies
*/
import AsyncBaseContainer from '../../async-base-container';
import * as driverManager from '../../driver-manager';
export default class GoogleAdPreviewTool extends AsyncBaseContainer {
constructor( driver, url ) {
super( driver, by.css( '.adt-root' ), url );
}
static getURL( screenSize, domain, location, query ) {
if ( screenSize === 'mobile' ) {
screenSize = 30001;
} else if ( screenSize === 'tablet' ) {
screenSize = 30002;
} else {
screenSize = 30000;
}
const url =
'https://adwords.google.com/anon/AdPreview' +
'?lang=' +
driverManager.currentLocale() +
'&loc=' +
location +
'&device=' +
screenSize +
'&st=' +
escape( query ) +
'&domain=' +
domain;
return url;
}
async getSearchPageUrl() {
const selector = by.css( 'iframe.iframe-preview' );
await this.driver.wait(
until.elementLocated( selector ),
this.explicitWaitMS,
'Could not locate the search results'
);
const iframe = await this.driver.findElement( selector );
await this.driver.wait(
until.elementIsVisible( iframe ),
this.explicitWaitMS,
'Could not see search results'
);
return await iframe.getAttribute( 'src' );
}
}