How to use checkSource method in Appium Xcuitest Driver

Best JavaScript code snippet using appium-xcuitest-driver

Run Appium Xcuitest Driver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Sign up Free
_

checkSource.spec.js

Source: checkSource.spec.js Github

copy
1const checkSource = require('../checkSource');
2
3it('should be defined', () => {
4  expect(checkSource).toBeDefined();
5});
6
7describe('#checkSource', () => {
8  it('should check the source in the sources', () => {
9    const source = 'fb';
10    const sources = [
11      {
12        title: 'fb',
13      },
14    ];
15    expect(() => checkSource(source, sources)).not.toThrow();
16  });
17
18  it('should throw error', () => {
19    const source = 'fb';
20    const sources = [
21      {
22        title: 'snap',
23      },
24    ];
25    expect(() => checkSource(source, sources)).toThrowErrorMatchingSnapshot();
26  });
27});
28
Full Screen

new-item.js

Source: new-item.js Github

copy
1define(["services/datacontext", "services/logger", objectbuilders.config, objectbuilders.router, "services/app", "viewmodels/_custom.forms.routes", "viewmodels/_custom.forms.dialogs", "viewmodels/_custom.forms.partial.views", "viewmodels/_custom.forms.scripts", objectbuilders.app],
2    function (context, logger, config, router, app, customForm, customDialog, partialView, customScript, app2) {
3        var checkSource = function (type, query) {
4            var tcs = new $.Deferred(),
5                count = 0,
6                checkExist = function () {
7
8                    if (count > 10) {
9                        return app2.showMessage("Please make sure your Subscriber Worker is started", "RX Developer", ["OK"])
10                        .done(function () {
11                            tcs.resolve(false);
12                        });
13                    }
14
15                    return context.loadOneAsync(type, query)
16                        .done(function (ed) {
17                            if (ed) {
18                                tcs.resolve(ed);
19                            } else {
20                                setTimeout(checkExist, 250);
21                                count++;
22                            }
23                        });
24                };
25
26            checkExist();
27            return tcs.promise();
28        },
29            addEntityDefinitionAsync = function () {
30
31                return app.showDialog("new.entity.definition.dialog")
32                      .then(function (dialog, result) {
33                          if (result === "OK") {
34                              return checkSource("EntityDefinition", "Id eq '" + ko.unwrap(dialog.id) + "'");
35                          }
36                          return Task.fromResult(0);
37                      }).then(function (ed) {
38                          if (ed)
39                              router.navigate("#entity.details/" + ko.unwrap(ed.Id));
40                      });
41            },
42            addValueObjectDefinitionAsync = function () {
43                return app.showDialog("new.value.object.definition.dialog")
44                         .then(function (dialog, result) {
45                             if (result === "OK") {
46                                 return checkSource("ValueObjectDefinition", "Id eq '" + ko.unwrap(dialog.id) + "'");
47                             }
48                             return Task.fromResult(0);
49                         }).then(function (ed) {
50                             if (ed)
51                                 router.navigate("#value.object.details/" + ko.unwrap(ed.Id));
52                         });
53            },
54            addWorkflowDefinitionAsync = function () {
55
56                return app.showDialog("new.workflow.definition.dialog")
57                        .then(function (dialog, result) {
58                            if (result === "OK") {
59                                return checkSource("WorkflowDefinition", "Id eq '" + ko.unwrap(dialog.id) + "'");
60                            }
61                            return Task.fromResult(0);
62                        }).then(function (ed) {
63                            if (ed)
64                                router.navigate("#workflow.definition.visual/" + ko.unwrap(ed.Id));
65                        });
66            },
67            addTransformDefinitionAsync = function () {
68                return app.showDialog("new.transform.definition.dialog")
69                        .then(function (dialog, result) {
70                            if (result === "OK") {
71                                return checkSource("TransformDefinition", "Id eq '" + ko.unwrap(dialog.id) + "'");
72                            }
73                            return Task.fromResult(0);
74                        }).then(function (ed) {
75                            if (ed)
76                                router.navigate("#transform.definition.edit/" + ko.unwrap(ed.Id));
77                        });
78            },
79            addTriggerAsync = function () {
80
81                return app.showDialog("new.trigger.dialog")
82                                      .then(function (dialog, result) {
83                                          if (result === "OK") {
84                                              return checkSource("Trigger", "Id eq '" + ko.unwrap(dialog.id) + "'");
85                                          }
86                                          return Task.fromResult(0);
87                                      }).then(function (trigger) {
88                                          if (trigger)
89                                              router.navigate("#trigger.setup/" + ko.unwrap(trigger.Id));
90                                      });
91            },
92            addAdapterAsync = function () {
93
94                var url = "";
95                return app.showDialog("new.adapter.dialog")
96                        .then(function (dialog, result) {
97                            if (result === "OK") {
98                                url = ko.unwrap(dialog.url);
99                                return checkSource("Adapter", "Id eq '" + ko.unwrap(dialog.id) + "'");
100                            }
101                            return Task.fromResult(0);
102                        }).then(function (ed) {
103                            if (ed)
104                                router.navigate(`#${url}`);
105                        });
106            },
107            addReportDefinitionAsync = function () {
108
109                return app.showDialog("new.report.definition.dialog")
110                        .then(function (dialog, result) {
111                            if (result === "OK") {
112                                return checkSource("ReportDefinition", "Id eq '" + ko.unwrap(dialog.id) + "'");
113                            }
114                            return Task.fromResult(0);
115                        }).then(function (ed) {
116                            if (ed)
117                                router.navigate("#reportdefinition.edit/" + ko.unwrap(ed.Id));
118                        });
119            },
120            addQueryEndpoint = function (ed) {
121
122                return app.showDialog("new.query.endpoint.dialog", function (dialog) {
123                    dialog.entity(ed);
124                })
125                        .then(function (dialog, result) {
126                            if (result === "OK") {
127                                return checkSource("QueryEndpoint", "Id eq '" + ko.unwrap(dialog.id) + "'");
128                            }
129                            return Task.fromResult(0);
130                        }).then(function (ed) {
131                            if (ed)
132                                router.navigate("#query.endpoint.designer/" + ko.unwrap(ed.Id));
133                        });
134            },
135            addEntityView = function (entityDefinition) {
136
137                return app.showDialog("new.entity.view.dialog", function (dialog) {
138                    dialog.entity(entityDefinition);
139                })
140                        .then(function (dialog, result) {
141                            if (result === "OK") {
142                                return checkSource("EntityView", "Id eq '" + ko.unwrap(dialog.id) + "'");
143                            }
144                            return Task.fromResult(0);
145                        }).then(function (ed) {
146                            if (ed)
147                                router.navigate("#entity.view.designer/" + ko.unwrap(ed.Id));
148                        });
149            },
150            addWorkflowForm = function (wd) {
151                return app.showDialog("new.workflow.form.dialog", function (dialog) {
152                    dialog.wd(wd);
153                })
154                        .then(function (dialog, result) {
155                            if (result === "OK") {
156                                return checkSource("WorkflowForm", "Id eq '" + ko.unwrap(dialog.id) + "'");
157                            }
158                            return Task.fromResult(0);
159                        }).then(function (wfrm) {
160                            if (wfrm)
161                                router.navigate("#workflow.form.designer/" + ko.unwrap(wfrm.WorkflowDefinitionId) + "/" + ko.unwrap(wfrm.Id));
162                        });
163            },
164            addEntityForm = function (entityDefinition) {
165                return app.showDialog("new.entity.form.dialog", function (dialog) {
166                    dialog.entity(entityDefinition);
167                })
168                        .then(function (dialog, result) {
169                            if (result === "OK") {
170                                return checkSource("EntityForm", "Id eq '" + ko.unwrap(dialog.id) + "'");
171                            }
172                            return Task.fromResult(0);
173                        }).then(function (ed) {
174                            if (ed)
175                                router.navigate(`#entity.form.designer/${ko.unwrap(ed.EntityDefinitionId)}/${ko.unwrap(ed.Id)}`);
176                        });
177            },
178            addReceivePort = function () {
179                return app.showDialog("new.receive.port.dialog")
180                        .then(function (dialog, result) {
181                            if (result === "OK") {
182                                return checkSource("ReceivePort", "Id eq '" + ko.unwrap(dialog.id) + "'");
183                            }
184                            return Task.fromResult(0);
185                        }).then(function (port) {
186                            if (port)
187                                router.navigate("#receive.port.designer/" + ko.unwrap(port.Id));
188                        });
189            },
190            addReceiveLocation = function () {
191
192                return app.showDialog("new.receive.location.dialog")
193                        .then(function (dialog, result) {
194                            if (result === "OK") {
195                                return checkSource("ReceiveLocation", `Id eq '${ko.unwrap(dialog.id)}'`);
196                            }
197                            return Task.fromResult(0);
198                        }).then(function (ed) {
199                            if (ed)
200                                router.navigate("#receive.location.list");
201                        });
202            },
203            addOperationEndpoint = function (entityDefinition) {
204
205                return app.showDialog("new.operation.endpoint.dialog", function (dialog) {
206                    dialog.entity(entityDefinition);
207                })
208                        .then(function (dialog, result) {
209                            if (result === "OK") {
210                                return checkSource("OperationEndpoint", "Id eq '" + ko.unwrap(dialog.id) + "'");
211                            }
212                            return Task.fromResult(0);
213                        }).then(function (ed) {
214                            if (ed)
215                                router.navigate("#operation.endpoint.designer/" + ko.unwrap(ed.Id));
216                        });
217            },
218            addPartialView = function (entityDefinition) {
219
220                return app.showDialog("new.partial.view.dialog", function (dialog) {
221                    dialog.entity(entityDefinition);
222                })
223                        .then(function (dialog, result) {
224                            if (result === "OK") {
225                                return checkSource("PartialView", "Id eq '" + ko.unwrap(dialog.id) + "'");
226                            }
227                            return Task.fromResult(0);
228                        }).then(function (ed) {
229                            if (ed)
230                                router.navigate("#partial.view.designer/" + ko.unwrap(ed.Entity) + "/" + ko.unwrap(ed.Id));
231                        });
232            },
233            addDashboard = function (entityDefinition) {
234
235                return app.showDialog("new.operation.endpoint.dialog", function (dialog) {
236                    dialog.entity(entityDefinition);
237                })
238                        .then(function (dialog, result) {
239                            if (result === "OK") {
240                                return checkSource("OperationEndpoint", "Id eq '" + ko.unwrap(dialog.id) + "'");
241                            }
242                            return Task.fromResult(0);
243                        }).then(function (ed) {
244                            if (ed)
245                                router.navigate("#operation.endpoint.designer/" + ko.unwrap(ed.Id));
246                        });
247            },
248            addDialog = function (entityDefinition) {
249
250                return app.showDialog("new.form.dialog.dialog", function (dialog) {
251                    dialog.entity(entityDefinition);
252                })
253                        .then(function (dialog, result) {
254                            if (result === "OK") {
255                                return checkSource("FormDialog", "Id eq '" + ko.unwrap(dialog.id) + "'");
256                            }
257                            return Task.fromResult(0);
258                        }).then(function (ed) {
259                            if (ed)
260                                router.navigate("#form.dialog.designer/" + ko.unwrap(ed.Entity) + "/" + ko.unwrap(ed.Id));
261                        });
262            },
263            addDataTransferDefinition = function (dtd) {
264                return app.showDialog("new.data.transfer.definition.dialog", function (dialog) {
265                    dialog.dtd(dtd);
266                })
267                    .then(function (dialog, result) {
268                        if (result === "OK") {
269                            return checkSource("DataTransferDefinition", "Id eq '" + ko.unwrap(dialog.id) + "'");
270                        }
271                        return Task.fromResult(0);
272                    }).then(function (ed) {
273                        if (ed)
274                            router.navigate("#data.import/" + ko.unwrap(ed.Id));
275                    });
276            };
277
278        var vm = {
279            addReceiveLocation: addReceiveLocation,
280            addReceivePort: addReceivePort,
281            addCustomFormAsync: customForm.addNew,
282            addDataTransferDefinition: addDataTransferDefinition,
283            addCustomDialogAsync: customDialog.addNewDialog,
284            addPartialViewAsync: partialView.addNewPartialView,
285            addCustomScriptAsync: customScript.addNew,
286            addValueObjectDefinitionAsync: addValueObjectDefinitionAsync,
287            addEntityDefinitionAsync: addEntityDefinitionAsync,
288            addAdapterAsync: addAdapterAsync,
289            addReportDefinitionAsync: addReportDefinitionAsync,
290            addTriggerAsync: addTriggerAsync,
291            addTransformDefinitionAsync: addTransformDefinitionAsync,
292            addQueryEndpoint: addQueryEndpoint,
293            addWorkflowForm: addWorkflowForm,
294            addEntityForm: addEntityForm,
295            addEntityView: addEntityView,
296            addDialog: addDialog,
297            addDashboard: addDashboard,
298            addPartialView: addPartialView,
299            addOperationEndpoint: addOperationEndpoint,
300            addWorkflowDefinitionAsync: addWorkflowDefinitionAsync
301        };
302
303        return vm;
304    });
Full Screen

test_source_checker.js

Source: test_source_checker.js Github

copy
1/**
2 * Copyright (c) 2019 Uber Technologies, Inc.
3 *
4 * <p>Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 * except in compliance with the License. You may obtain a copy of the License at
6 *
7 * <p>http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * <p>Unless required by applicable law or agreed to in writing, software distributed under the
10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11 * express or implied. See the License for the specific language governing permissions and
12 * limitations under the License.
13 */
14
15const chai = require('chai');
16const expect = chai.expect;
17const source_checker = require('../src/source_checker');
18const checkSource = source_checker.checkSource;
19
20describe('source_checker', () => {
21    describe('#checkSource', () => {
22        it('should throw error on invalid source filepath.', () => {
23            expect(checkSource.bind(checkSource, 'random_source_file_that_does_not_exist.js', true)).to.throw(
24                'File random_source_file_that_does_not_exist.js not found',
25            );
26        });
27
28        it('should throw error if source file is not JS.', () => {
29            // fs module uses process.cwd() to figure relative path so `npm test` run in root wont't need ../
30            expect(checkSource.bind(checkSource, 'config/properties.json', true)).to.throw(
31                'Input config/properties.json is not a javascript file',
32            );
33        });
34    });
35});
36
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Appium Xcuitest Driver on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)