-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnavigate.js
303 lines (259 loc) · 9.24 KB
/
navigate.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
'use strict';
import * as webdriver from 'selenium-webdriver';
import * as jsforce from 'jsforce';
import * as url from 'url';
let By = webdriver.By;
let until = webdriver.until;
/**
* @param {webdriver.WebDriver} driver
*/
export async function gotoSetup(driver) {
return (await driver.get('https://eu5.salesforce.com/setup/forcecomHomepage.apexp'));
}
/**
* @param {jsforce.Connection} jsforceConn
* @param {string} class_
* @param {string} cronExpr
*/
export async function createScheduledApexWithJsforce(jsforceConn, class_, cronExpr) {
let apexCode = `${class_} inst = new ${class_}();
String sch = '${cronExpr}';
String jobID = System.schedule('auto scheduled job ${class_}', sch, inst);
System.debug(jobID);`;
let resultSchedule = await jsforceConn.tooling.executeAnonymous(apexCode);
if (resultSchedule.success !== true) {
throw resultSchedule;
}
let cronTriggers = await fetchCronTriggers(jsforceConn);
return cronTriggers.records[0];
}
/**
* @param {jsforce.Connection} jsforceConn
*/
export async function fetchCronTriggers(jsforceConn) {
return (await jsforceConn.query(`
SELECT Id, CronJobDetail.Id, CronJobDetail.Name, CronJobDetail.JobType
FROM CronTrigger`));
}
/**
* @param {jsforce.Connection} jsforceConn
* @param {string} jobName
* @returns {Array.<Record>}
*/
export async function fetchCronTriggersByName(jsforceConn, jobName) {
//CronJobDetail
return (await jsforceConn.query(`
SELECT Id, CronJobDetail.Id, CronJobDetail.Name, CronJobDetail.JobType
FROM CronTrigger
WHERE CronJobDetail.Name = ${jobName}`)).records;
}
/**
* @param {jsforce.Connection} jsforceConn
* @param {string} jobId
*/
export async function removeScheduledApexWithJsforce(jsforceConn, jobId) {
let apexCode = `System.abortJob('${jobId}');`;
let resultAbort = await jsforceConn.tooling.executeAnonymous(apexCode);
console.log(resultAbort);
if (resultAbort.success !== true) {
throw resultAbort;
}
return resultAbort;
}
/**
* @param {jsforce.Connection} jsforceConn
* @param {string} className
* @returns {Record}
*/
export async function fetchApexClassByName(jsforceConn, className) {
let q = `SELECT Id FROM ApexClass WHERE Name = '${className}'`;
let classResult = (await jsforceConn.query(q)).records;
if (classResult.length < 1) {
throw 'No such class found';
}
return classResult[0];
}
/**
* @param {jsforce.Connection} jsforceConn
* @param {string} className
* @returns {Record}
*/
export async function fetchEmailServicesByClassName(jsforceConn, className) {
let class_ = await fetchApexClassByName(jsforceConn, className);
let q = `SELECT AddressInactiveAction,ApexClassId,AttachmentOption,AuthenticationFailureAction,
AuthorizationFailureAction,AuthorizedSenders,CreatedById,CreatedDate,ErrorRoutingAddress,FunctionInactiveAction,
FunctionName,Id,IsActive,IsAuthenticationRequired,IsErrorRoutingEnabled,IsTextAttachmentsAsBinary,IsTlsRequired,
LastModifiedById,LastModifiedDate,OverLimitAction,SystemModstamp
FROM EmailServicesFunction
WHERE ApexClassId = '${class_.Id}'`;
let emailServicesResult = (await jsforceConn.query(q)).records;
if (emailServicesResult.length < 1) {
throw 'No such e-mail service found';
}
return emailServicesResult[0];
}
/**
* @param {jsforce.Connection} jsforceConn
* @returns {Array.<Record>}
*/
export async function fetchEmailServices(jsforceConn) {
let q = `
SELECT AddressInactiveAction,ApexClassId,AttachmentOption,AuthenticationFailureAction,AuthorizationFailureAction,
AuthorizedSenders,CreatedById,CreatedDate,ErrorRoutingAddress,FunctionInactiveAction,FunctionName,Id,IsActive,
IsAuthenticationRequired,IsErrorRoutingEnabled,IsTextAttachmentsAsBinary,IsTlsRequired,LastModifiedById,
LastModifiedDate,OverLimitAction,SystemModstamp
FROM EmailServicesFunction`;
return (await jsforceConn.query(q)).records;
}
/**
* @param {jsforce.Connection} jsforceConn
* @returns {Array.<Record>}
*/
export async function fetchEmailServiceAddresses(jsforceConn) {
let q = `
SELECT AuthorizedSenders,CreatedById,CreatedDate,EmailDomainName,FunctionId,Id,IsActive,LastModifiedById,
LastModifiedDate,LocalPart,RunAsUserId,SystemModstamp
FROM EmailServicesAddress`;
return (await jsforceConn.query(q)).records;
}
/**
* @param {jsforce.Connection} jsforceConn
* @param {string} functionId
* @returns {Array.<Record>}
*/
export async function fetchEmailServiceAddressesByFunctionId(jsforceConn, functionId) {
let q = `
SELECT AuthorizedSenders,CreatedById,CreatedDate,EmailDomainName,FunctionId,Id,IsActive,LastModifiedById,
LastModifiedDate,LocalPart,RunAsUserId,SystemModstamp
FROM EmailServicesAddress
WHERE FunctionId = '${functionId}'`;
return (await jsforceConn.query(q)).records;
}
/**
* @param {jsforce.Connection} jsforceConn
* @param classId
*
* https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_emailservicesfunction.htm
*/
export async function createEmailService(jsforceConn, classId) {
let service = {
//AddressInactiveAction: '',
ApexClassId: classId,
AttachmentOption: 3, // accepts any attachment type
//AuthenticationFailureAction: '',
//AuthorizationFailureAction: '',
//AuthorizedSenders: '',
//ErrorRoutingAddress: '',
//FunctionInactiveAction: '',
FunctionName: 'InboundEmailHandler',
IsActive: true
//IsAuthenticationRequired: '',
//IsErrorRoutingEnabled: '',
//IsTextAttachmentsAsBinary: '',
//IsTextTruncated: '',
//IsTlsRequired: '',
//OverLimitAction: ''
};
return await jsforceConn.sobject('EmailServicesFunction').insert(service);
}
/**
* @param {jsforce.Connection} jsforceConn
* @param {string} emailServiceId
*
* https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_emailservicesaddress.htm
*/
export async function createEmailServiceAddress(jsforceConn, emailServiceId) {
let address = {
//AuthorizedSenders: '',
//EmailDomainName: '',
FunctionId: emailServiceId,
IsActive: true,
//AddressInactiveAction: '',
LocalPart: 'test-InboundEmailHandler',
RunAsUserId: jsforceConn.userInfo.id
};
return await jsforceConn.sobject('EmailServicesAddress').insert(address);
}
/**
* @param {webdriver.WebDriver} driver
* @param {string} class_
*/
export async function createScheduledApex(driver, class_) {
let endDate = '20-10-2099';
await driver.get('https://eu5.salesforce.com/ui/setup/apex/batch/ScheduleBatchApexPage');
await driver.findElement(By.id('job_name')).sendKeys('Auto planned ' + class_);
await driver.findElement(By.id('ac')).sendKeys(class_);
await driver.findElement(By.id('ww00')).click();
await driver.findElement(By.id('ww10')).click();
await driver.findElement(By.id('ww20')).click();
await driver.findElement(By.id('ww30')).click();
await driver.findElement(By.id('ww40')).click();
await driver.findElement(By.id('ww50')).click();
await driver.findElement(By.id('ww60')).click();
let endDateElem = driver.findElement(By.id('end0'));
await endDateElem.clear();
await endDateElem.sendKeys(endDate);
// blur the focus for the datepicker
await driver.findElement(By.tagName('body')).click();
let dropdown = driver.findElement(By.id('pst0'));
await dropdown.click();
await dropdown.findElement(By.css('option[value=\'0:00\']')).click();
await driver.findElement(By.css('form[action=\'/ui/setup/apex/batch/ScheduleBatchApexPage?setupid=ScheduledJobs\']'))
.submit();
}
/**
* @param {webdriver.WebDriver} driver
* @param {string} username
* @param {string} password
* @param {string} loginUrl
*/
export async function login(driver, username, password, loginUrl) {
await driver.get(loginUrl);
// Login
await driver.findElement(By.id('username')).sendKeys(username);
await driver.findElement(By.id('password')).sendKeys(password);
await driver.findElement(By.id('Login')).click();
// Wait for page load
const appMenuLocator = By.id('toolbar');
await driver.wait(until.elementLocated(appMenuLocator));
}
/**
* @param {webdriver.WebDriver} driver
*/
export async function openLightningProcessBuilder(driver) {
const processBuilderUrl = `${getInstanceUrl(driver)}/processui/processui.app`;
console.log('URL Lightning Process Builder', processBuilderUrl);
await driver.get(processBuilderUrl);
// Wait while the proces builder page loads
await driver.wait(until.elementLocated(By.id('label')));
}
/**
* @param {webdriver.WebDriver} driver
* @returns {string}
*/
export async function getInstanceUrl(driver) {
let currentUrl = await driver.getCurrentUrl();
let currentUrlParsed = url.parse(currentUrl);
return `${currentUrlParsed.protocol}//${currentUrlParsed.hostname}`;
}
/**
* @param {webdriver.WebDriver} driver
* @param {string} sobjectName
*/
export async function openSObjectTab(driver, sobjectName) {
await driver.findElement(By.css(`.wt-${sobjectName.replace('__c', '')} a`)).click();
}
/**
* @param {webdriver.Locator} locator
* @returns {webdriver.until.Condition}
*/
export function elemIsVisible(locator) {
return new until.Condition('wait for visible of elem', function(_driver) {
try {
_driver.findElement(locator);
return true;
} catch (err) {
return false;
}
});
}