How to use getProperties method in Puppeteer

Best JavaScript code snippet using puppeteer

Run Puppeteer automation tests on LambdaTest cloud grid

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

server.js

Source: server.js Github

copy
1require('dotenv').config();
2const path = require('path');
3const config = require('./config');
4const fs = require('fs');
5var express = require('express');
6const app = express();
7const prod = config.getProperties('prod');
8
9var global_json = {
10  "secure" : config.getProperties().secure,
11  "insecure": config.getProperties().insecure,
12  "web_port" : config.getProperties().web_port,
13  "web_endpoint": config.getProperties().web_endpoint,
14  "api_port" : config.getProperties().api_port,
15  "api_endpoint": config.getProperties().api_endpoint,
16  "client_id": config.getProperties().client_id,
17  "node_port": config.getProperties().node_port
18}
19
20fs.writeFile("config/global.json", JSON.stringify(global_json), function(err) {
21    if(err) {
22        return console.log(err);
23    }
24    console.log("The file was saved!");
25});
26console.log(config.getProperties().node_port);
27app.listen(config.getProperties().node_port, () => console.log('Listening on port: ' + config.getProperties().node_port));
28app.use(express.static(__dirname));
29app.use('/media', express.static(path.join(__dirname, "..", "API"))); //__dir and not _dir
30
31app.use((req, res, next) => {
32  console.log('Time: ', Date.now());
33  next();
34});
35
Full Screen

get-properties.spec.js

Source: get-properties.spec.js Github

copy
1const getProperties = require('../../lib/helpers/get-properties')
2
3describe('getProperties', () => {
4  it('is a function', () => {
5    expect(getProperties).toBeInstanceOf(Function)
6  })
7
8  it('returns {} when no arguments are passed', () => {
9    const emptyObj = getProperties()
10    expect(emptyObj).toEqual({})
11  })
12
13  it('returns {} when invalid arguments are passed', () => {
14    const invalid1 = getProperties({})
15
16    const invalid2 = getProperties('hello')
17
18    const invalid3 = getProperties(() => 1)
19
20    expect(invalid1).toEqual({})
21    expect(invalid2).toEqual({})
22    expect(invalid3).toEqual({})
23  })
24
25  it('returns {} if options is an empty array', () => {
26    const result = getProperties([])
27
28    expect(result).toEqual({})
29  })
30
31  it('returns first element of options array', () => {
32    const option1 = [{ foo: 'bar', one: 1 }]
33    const option2 = [{ foo: 'bar', one: 1, two: 2 }, 'more', 'items']
34
35    const result1 = getProperties(option1)
36
37    const result2 = getProperties(option2)
38
39    expect(result1).toEqual(option1[0])
40    expect(result2).toEqual(option2[0])
41  })
42})
43
Full Screen

system_js_test.js

Source: system_js_test.js Github

copy
1	var sys_get_property = [
2	
3	{
4		testName		:	"VT300-005 | call getProperty with country | US",
5		propertyName	:	"country",
6		osType			: 	["WINDOWS","ANDROID","APPLE","WP8","WINDOWS_DESKTOP"]
7	},
8	{
9		testName		:	"VT300-006 | call getProperty with deviceName | MC75",
10		propertyName	:	"deviceName",
11		osType			: 	["WINDOWS","ANDROID","APPLE","WP8","WINDOWS_DESKTOP"]
12	},
13	{
14		testName		:	"VT300-007 | call getProperty with deviceOwnerEmail | ",
15		propertyName	:	"deviceOwnerEmail",
16		osType			: 	["ANDROID"]
17	},
18	{
19		testName		:	"VT300-008 | call getProperty with deviceOwnerName | ",
20		propertyName	:	"deviceOwnerName",
21		osType			: 	["ANDROID"]
22	},
23	{
24		testName		:	"VT300-009 | call getProperty with devicePushId | ",
25		propertyName	:	"devicePushId",
26		osType			: 	["WINDOWS","ANDROID","APPLE","WP8","WINDOWS_DESKTOP"]
27	},
28	{
29		testName		:	"VT300-010 | call getProperty with freeServerPort | ",
30		propertyName	:	"freeServerPort",
31		osType			: 	["WINDOWS","ANDROID","APPLE","WP8","WINDOWS_DESKTOP"]
32	},
33	{
34		testName		:	"VT300-011 | call getProperty with hasCalendar | ",
35		propertyName	:	"hasCalendar",
36		osType			: 	["WINDOWS","ANDROID","APPLE","WP8","WINDOWS_DESKTOP"]
37	},
38	{
39		testName		:	"VT300-012 | call getProperty with hasCamera | ",
40		propertyName	:	"hasCamera",
41		osType			: 	["WINDOWS","ANDROID","APPLE","WP8","WINDOWS_DESKTOP"]
42	},
43	{
44		testName		:	"VT300-017 | call getProperty with isRhoSimulator | ",
45		propertyName	:	"isRhoSimulator",
46		osType			: 	["WINDOWS","ANDROID","APPLE","WP8","WINDOWS_DESKTOP"]
47	},
48	{
49		testName		:	"VT300-018 | call getProperty with hasTouchscreen | ",
50		propertyName	:	"hasTouchscreen",
51		osType			: 	["WINDOWS","ANDROID","APPLE","WP8","WINDOWS_DESKTOP"]
52	},
53	{
54		testName		:	"VT300-023 | call getProperty with isEmulator | ",
55		propertyName	:	"isEmulator",
56		osType			: 	["WINDOWS","ANDROID","APPLE","WP8","WINDOWS_DESKTOP"]
57	},
58	{
59		testName		:	"VT300-024 | call getProperty with isSymbolDevice | ",
60		propertyName	:	"isSymbolDevice",
61		osType			: 	["WINDOWS","ANDROID","APPLE","WP8","WINDOWS_DESKTOP"]
62	},
63	{
64		testName		:	"VT300-026 | default localServerPort | ",
65		propertyName	:	"localServerPort",
66		osType			: 	["WINDOWS","ANDROID","APPLE","WP8","WINDOWS_DESKTOP"]
67	},
68	{
69		testName		:	"VT300-033 | call getProperty with oemInfo | ",
70		propertyName	:	"oemInfo",
71		osType			: 	["WINDOWS","ANDROID","SYMBOL"]
72	},
73	
74	{
75		testName		:	"VT300-034 | call getProperty with osVersion | ",
76		propertyName	:	"osVersion",
77		osType			: 	["WINDOWS","ANDROID","APPLE","WP8","WINDOWS_DESKTOP"]
78	},
79	
80	{
81		testName		:	"VT300-035 | call getProperty with phoneId | ",
82		propertyName	:	"phoneId",
83		osType			: 	["WINDOWS","ANDROID"]
84	},
85	{
86		testName		:	"VT300-038 | call getProperty with ppiX | ",
87		propertyName	:	"ppiX",
88		osType			: 	["WINDOWS","ANDROID","APPLE","WP8","WINDOWS_DESKTOP"]
89	},
90	{
91		testName		:	"VT300-039 | call getProperty with ppiY | ",
92		propertyName	:	"ppiY",
93		osType			: 	["WINDOWS","ANDROID","APPLE","WP8","WINDOWS_DESKTOP"]
94	},
95	{
96		testName		:	"VT300-040 | call getProperty with realScreenHeight | ",
97		propertyName	:	"realScreenHeight",
98		osType			: 	["WINDOWS","ANDROID","APPLE","WP8","WINDOWS_DESKTOP"]
99	},
100	{
101		testName		:	"VT300-041 | call getProperty with realScreenWidth | ",
102		propertyName	:	"realScreenWidth",
103		osType			: 	["WINDOWS","ANDROID","APPLE","WP8","WINDOWS_DESKTOP"]
104	},
105	{
106		testName		:	"VT300-046 | call getProperty with screenHeight | ",
107		propertyName	:	"screenHeight",
108		osType			: 	["WINDOWS","ANDROID","APPLE","WP8","WINDOWS_DESKTOP"]
109	},
110	{
111		testName		:	"VT300-047 | call getProperty with screenWidth | ",
112		propertyName	:	"screenWidth",
113		osType			: 	["WINDOWS","ANDROID","APPLE","WP8","WINDOWS_DESKTOP"]
114	},
115	{
116		testName		:	"VT300-059 | call getProperty with uuid | ",
117		propertyName	:	"uuid",
118		osType			: 	["WINDOWS","ANDROID","SYMBOL"]
119	},
120	{
121		testName		:	"VT300-060 | call getProperty with webviewFramework | ",
122		propertyName	:	"webviewFramework",
123		osType			: 	["WINDOWS","ANDROID","APPLE","WP8","WINDOWS_DESKTOP"]
124	}
125	];
126	
127	var sys_get_properties = [
128	
129	{
130		testName		:	"VT300-134 | call getproperties with country | ",
131		propertyName	:	"country",
132		osType			: 	["WINDOWS","ANDROID","APPLE","WP8","WINDOWS_DESKTOP"]
133	},
134	{
135		testName		:	"VT300-135 | call getproperties with deviceName | ",
136		propertyName	:	"deviceName",
137		osType			: 	["WINDOWS","ANDROID","APPLE","WP8","WINDOWS_DESKTOP"]
138	},
139	{
140		testName		:	"VT300-136 | call getproperties with deviceOwnerEmail | ",
141		propertyName	:	"deviceOwnerEmail",
142		osType			: 	["ANDROID"]
143	},
144	{
145		testName		:	"VT300-137 | call getproperties with deviceOwnerName | ",
146		propertyName	:	"deviceOwnerName",
147		osType			: 	["ANDROID"]
148	},
149	{
150		testName		:	"VT300-138 | call getproperties with devicePushId | ",
151		propertyName	:	"devicePushId",
152		osType			: 	["WINDOWS","ANDROID","APPLE","WP8","WINDOWS_DESKTOP"]
153	},
154	{
155		testName		:	"VT300-139 | call getproperties with freeServerPort | ",
156		propertyName	:	"freeServerPort",
157		osType			: 	["WINDOWS","ANDROID","APPLE","WP8","WINDOWS_DESKTOP"]
158	},
159	{
160		testName		:	"VT300-140 | call getproperties with hasCalendar | ",
161		propertyName	:	"hasCalendar",
162		osType			: 	["WINDOWS","ANDROID","APPLE","WP8","WINDOWS_DESKTOP"]
163	},
164	{
165		testName		:	"VT300-141 | call getproperties with hasCamera | ",
166		propertyName	:	"hasCamera",
167		osType			: 	["WINDOWS","ANDROID","APPLE","WP8","WINDOWS_DESKTOP"]
168	},
169	{
170		testName		:	"VT300-146 | call getproperties with hasSqlite | ",
171		propertyName	:	"hasSqlite",
172		osType			: 	["WINDOWS","ANDROID","APPLE","WP8","WINDOWS_DESKTOP"]
173	},
174	{
175		testName		:	"VT300-147 | call getproperties with hasTouchscreen | ",
176		propertyName	:	"hasTouchscreen",
177		osType			: 	["WINDOWS","ANDROID","APPLE","WP8","WINDOWS_DESKTOP"]
178	},
179	{
180		testName		:	"VT300-151 | Run the application on device, call getproperties with isEmulator | ",
181		propertyName	:	"isEmulator",
182		osType			: 	["WINDOWS","ANDROID","APPLE","WP8","WINDOWS_DESKTOP"]
183	},
184	{
185		testName		:	"VT300-152 | call getproperties with isSymbolDevice | ",
186		propertyName	:	"isSymbolDevice",
187		osType			: 	["WINDOWS","ANDROID","APPLE","WP8","WINDOWS_DESKTOP"]
188	},
189	{
190		testName		:	"VT300-153 | getproperties with localServerPort | ",
191		propertyName	:	"localServerPort",
192		osType			: 	["WINDOWS","ANDROID","APPLE","WP8","WINDOWS_DESKTOP"]
193	},
194	{
195		testName		:	"VT300-154 | call getproperties with locale | ",
196		propertyName	:	"locale",
197		osType			: 	["WINDOWS","ANDROID","APPLE","WP8","WINDOWS_DESKTOP"]
198	},
199	{
200		testName		:	"VT300-161 | call getproperties with oemInfo | ",
201		propertyName	:	"oemInfo",
202		osType			: 	["WINDOWS","ANDROID","SYMBOL"]
203	},
204	{
205		testName		:	"VT300-162 | call getproperties with osVersion | ",
206		propertyName	:	"osVersion",
207		osType			: 	["WINDOWS","ANDROID","APPLE","WP8","WINDOWS_DESKTOP"]
208	},
209	{
210		testName		:	"VT300-163 | call getproperties with phoneId | ",
211		propertyName	:	"phoneId",
212		osType			: 	["WINDOWS","ANDROID","APPLE","WP8","WINDOWS_DESKTOP"]
213	},
214	{
215		testName		:	"VT300-164 | call getproperties with phoneNumber | ",
216		propertyName	:	"phoneNumber",
217		osType			: 	["WINDOWS","ANDROID","APPLE","WP8","WINDOWS_DESKTOP"]
218	},
219	{
220		testName		:	"VT300-165 | call getproperties with platform | ",
221		propertyName	:	"platform",
222		osType			: 	["WINDOWS","ANDROID","APPLE","WP8","WINDOWS_DESKTOP"]
223	},
224	{
225		testName		:	"VT300-166 | call getproperties with ppiX | ",
226		propertyName	:	"ppiX",
227		osType			: 	["WINDOWS","ANDROID","APPLE","WP8","WINDOWS_DESKTOP"]
228	},
229	{
230		testName		:	"VT300-167 | call getproperties with ppiY | ",
231		propertyName	:	"ppiY",
232		osType			: 	["WINDOWS","ANDROID","APPLE","WP8","WINDOWS_DESKTOP"]
233	},
234	{
235		testName		:	"VT300-168 | call getproperties with realScreenHeight | ",
236		propertyName	:	"realScreenHeight",
237		osType			: 	["WINDOWS","ANDROID","APPLE","WP8","WINDOWS_DESKTOP"]
238	},
239	{
240		testName		:	"VT300-169 | call getproperties with realScreenWidth | ",
241		propertyName	:	"realScreenWidth",
242		osType			: 	["WINDOWS","ANDROID","APPLE","WP8","WINDOWS_DESKTOP"]
243	},
244	{
245		testName		:	"VT300-172 | call getproperties with screenHeight | ",
246		propertyName	:	"screenHeight",
247		osType			: 	["WINDOWS","ANDROID","APPLE","WP8","WINDOWS_DESKTOP"]
248	},
249	{
250		testName		:	"VT300-173 | call getproperties with screenWidth | ",
251		propertyName	:	"screenWidth",
252		osType			: 	["WINDOWS","ANDROID","APPLE","WP8","WINDOWS_DESKTOP"]
253	},
254	{
255		testName		:	"VT300-183 | call getproperties with uuid | ",
256		propertyName	:	"uuid",
257		osType			: 	["WINDOWS","ANDROID","SYMBOL"]
258	},
259	{
260		testName		:	"VT300-184 | call getproperties with webviewFramework | ",
261		propertyName	:	"webviewFramework",
262		osType			: 	["WINDOWS","ANDROID","APPLE","WP8","WINDOWS_DESKTOP"]
263	}
264
265	];
Full Screen

report.js

Source: report.js Github

copy
1$(document).ready(function() {
2
3    var features = [];
4
5    var featureType = $.trim($("#feature-type").html());
6
7    $(".row-data").each(function() {
8        var s = $(this).children('td').first().text();
9        features.push(s);
10    });
11    var fieldArray = [];
12    var subbasinArray = [];
13    var fieldArray2 = [];
14    var subbasinArray2 = [];
15    function Subbasin(id, feature, flow, sediment, tn, tp) {
16        this.id = id;
17        this.feature = feature;
18        this.flow = flow;
19        this.sediment = sediment;
20        this.tn = tn;
21        this.tp = tp;
22    }
23
24    function Field(id, feature, flow, sediment, tn, tp) {
25        this.id = id;
26        this.feature = feature;
27        this.flow = flow;
28        this.sediment = sediment;
29        this.tn = tn;
30        this.tp = tp;
31    }
32    // var fieldArray = [];
33    // var subbasinArray = [];
34
35    var layerSwitch = 1;
36    var layerSwitch2 = 1;
37
38
39    var Great = 'rgba(53, 191, 0, 0.6)';
40    var Good = 'rgba(115, 197, 0, 0.6)';
41    var Normal = 'rgba(181, 203, 0, 0.6)';
42    var Slight = 'rgba(210, 168, 0, 0.6)';
43    var Bad = 'rgba(216, 170, 0, 0.6)';
44    var Severe = 'rgba(229, 0, 26, 0.6)';
45
46    var SeverityLevel = {
47        "Great": Great,
48        "Good": Good,
49        "Normal": Normal,
50        "Slight": Slight,
51        "Bad": Bad,
52        "Severe": Severe
53    };
54
55    var defaultStyle = new ol.style.Style({
56        fill: new ol.style.Fill({
57            color: [250, 250, 250, 0.6]
58        }),
59        stroke: new ol.style.Stroke({
60            color: [220, 220, 220, 1],
61            width: 1
62        })
63    });
64
65    var boundaryStyle = new ol.style.Style({
66        // fill: new ol.style.Fill({
67        //     color: 'rgba(17,34,68,0.6)'
68        // }),
69        stroke: new ol.style.Stroke({
70            color: 'black',
71        })
72    });
73
74    var styleCache = {};
75
76    function styleSedimentFunction(feature, resolution) {
77        var properties = feature.getProperties();
78        var level = feature.getProperties().sedimentlevel;
79        var value = feature.getProperties().sediment;
80        value = value.toFixed(2);
81        if (!level || !SeverityLevel[level]) {
82            return [defaultStyle];
83        }
84        if (!styleCache[level]) {
85            styleCache[level] = new ol.style.Style({
86                fill: new ol.style.Fill({
87                    color: SeverityLevel[level]
88                }),
89                stroke: new ol.style.Stroke({
90                    color: "white",
91                    width: 1
92                }),
93                text: new ol.style.Text({
94                    // text: value,
95
96                    font: '12px Calibri,sans-serif',
97                    fill: new ol.style.Fill({ color: '#000' }),
98                    stroke: new ol.style.Stroke({
99                        color: '#fff',
100                        width: 2
101                    }),
102                    // get the text from the feature - `this` is ol.Feature
103                })
104            });
105        }
106        styleCache[level].getText().setText(value);
107
108        return [styleCache[level]];
109    }
110
111    function styleFlowFunction(feature, resolution) {
112        var properties = feature.getProperties();
113        var level = feature.getProperties().flowlevel;
114        var value = feature.getProperties().flow;
115        value = value.toFixed(2);
116        if (!level || !SeverityLevel[level]) {
117            return [defaultStyle];
118        }
119        if (!styleCache[level]) {
120            styleCache[level] = new ol.style.Style({
121                fill: new ol.style.Fill({
122                    color: SeverityLevel[level]
123                }),
124                stroke: new ol.style.Stroke({
125                    color: "white",
126                    width: 1
127                }),
128                text: new ol.style.Text({
129                    // text: value,
130
131                    font: '12px Calibri,sans-serif',
132                    fill: new ol.style.Fill({ color: '#000' }),
133                    stroke: new ol.style.Stroke({
134                        color: '#fff',
135                        width: 2
136                    }),
137                    // get the text from the feature - `this` is ol.Feature
138                })
139            });
140        }
141        styleCache[level].getText().setText(value);
142
143        return [styleCache[level]];
144    }
145
146    function styleTpFunction(feature, resolution) {
147        var properties = feature.getProperties();
148        var level = feature.getProperties().tplevel;
149        var value = feature.getProperties().tp;
150        value = value.toFixed(2);
151        if (!level || !SeverityLevel[level]) {
152            return [defaultStyle];
153        }
154        if (!styleCache[level]) {
155            styleCache[level] = new ol.style.Style({
156                fill: new ol.style.Fill({
157                    color: SeverityLevel[level]
158                }),
159                stroke: new ol.style.Stroke({
160                    color: "white",
161                    width: 1
162                }),
163                text: new ol.style.Text({
164                    // text: value,
165
166                    font: '12px Calibri,sans-serif',
167                    fill: new ol.style.Fill({ color: '#000' }),
168                    stroke: new ol.style.Stroke({
169                        color: '#fff',
170                        width: 2
171                    }),
172                    // get the text from the feature - `this` is ol.Feature
173                })
174            });
175        }
176        styleCache[level].getText().setText(value);
177
178        return [styleCache[level]];
179    }
180
181    function styleTnFunction(feature, resolution) {
182        var properties = feature.getProperties();
183        var level = feature.getProperties().tnlevel;
184        var value = feature.getProperties().tn;
185        value = value.toFixed(2);
186        if (!level || !SeverityLevel[level]) {
187            return [defaultStyle];
188        }
189        if (!styleCache[level]) {
190            styleCache[level] = new ol.style.Style({
191                fill: new ol.style.Fill({
192                    color: SeverityLevel[level]
193                }),
194                stroke: new ol.style.Stroke({
195                    color: "white",
196                    width: 1
197                }),
198                text: new ol.style.Text({
199                    // text: value,
200                    font: '12px Calibri,sans-serif',
201                    fill: new ol.style.Fill({ color: '#000' }),
202                    stroke: new ol.style.Stroke({
203                        color: '#fff',
204                        width: 2
205                    }),
206                })
207            });
208        }
209        styleCache[level].getText().setText(value);
210        return [styleCache[level]];
211    }
212
213    var tiledRaster = new ol.layer.Tile({
214        source: new ol.source.OSM()
215    });
216
217    var streamStyle = new ol.style.Style({
218        stroke: new ol.style.Stroke({
219            color: 'rgba(99,179,235,0.6)',
220            width: 2
221        }),
222
223    });
224
225    var streamJsonp = new ol.layer.Vector({
226        source: new ol.source.Vector({
227            url: '/assets/data/geojson/stream.geojson',
228            format: new ol.format.GeoJSON()
229        }),
230        style: streamStyle,
231        zIndex: 20
232    });
233    var subbasinStyle = new ol.style.Style({
234        fill: new ol.style.Fill({
235            color: 'rgba(17,34,68,0.6)'
236        }),
237        stroke: new ol.style.Stroke({
238            color: 'white'
239        })
240    });
241
242    var subbasinJsonp = new ol.layer.Vector({
243        source: new ol.source.Vector({
244            url: '/assets/data/geojson/basinoutput.json',
245            format: new ol.format.GeoJSON()
246        }),
247        style: subbasinStyle
248    });
249
250    subbasinJsonp.getSource().on('change', function(event) {
251       var subbasinFeatures = subbasinJsonp.getSource().getFeatures();
252        for (i = 0; i < subbasinFeatures.length; i++) {
253            var subbasin = new Subbasin();
254            subbasin.id = subbasinFeatures[i].getProperties().name;
255            subbasin.feature = subbasinFeatures[i];
256            subbasin.flow = subbasinFeatures[i].getProperties().flow;
257            subbasin.sediment = subbasinFeatures[i].getProperties().sediment;
258            subbasin.tp = subbasinFeatures[i].getProperties().tp;
259            subbasin.tn = subbasinFeatures[i].getProperties().tn;
260            subbasinArray.push(subbasin);
261        }
262        if (featureType == "subbasin") {
263            for (var m = 0; m < features.length; m++) {
264                for (var n = 0; n < subbasinArray.length; n++) {
265                    if (features[m] === subbasinArray[n].id) {
266
267
268                        $("#result-table table tbody").append('<tr><td>' + subbasinArray[n].id + '</td><td>' + subbasinArray[n].flow + '</td><td>' + subbasinArray[n].sediment + '</td><td>' + subbasinArray[n].tp + '</td><td>' + subbasinArray[n].tn + '</td> </tr>');
269
270                    }
271                }
272            }
273
274        }
275
276    });
277
278    var fieldStyle = new ol.style.Style({
279        fill: new ol.style.Fill({
280            color: 'rgba(113,113,113,0.8)'
281        }),
282        stroke: new ol.style.Stroke({
283            color: 'white'
284        })
285    });
286
287    var fieldJsonp = new ol.layer.Vector({
288        source: new ol.source.Vector({
289            url: '/assets/data/geojson/fieldoutput.json',
290            format: new ol.format.GeoJSON()
291        }),
292        style: fieldStyle
293    });
294
295    fieldJsonp.getSource().on('change', function(event) {
296        var fieldFeatures = fieldJsonp.getSource().getFeatures();
297        for (i = 0; i < fieldFeatures.length; i++) {
298            var field = new Field();
299            field.id = fieldFeatures[i].getProperties().name;
300            field.feature = fieldFeatures[i];
301            field.flow = fieldFeatures[i].getProperties().flow;
302            field.sediment = fieldFeatures[i].getProperties().sediment;
303            field.tp = fieldFeatures[i].getProperties().tp;
304            field.tn = fieldFeatures[i].getProperties().tn;
305            fieldArray.push(field);
306        }
307        if (featureType === "field") {
308            for (var m = 0; m < features.length; m++) {
309                for (var n = 0; n < fieldArray.length; n++) {
310                    if (features[m] === fieldArray[n].id) {
311                        $("#result-table table tbody").append('<tr><td>' + fieldArray[n].id + '</td><td>' + fieldArray[n].flow + '</td><td>' + fieldArray[n].sediment + '</td><td>' + fieldArray[n].tp + '</td><td>' + fieldArray[n].tn + '</td> </tr>');
312                        // fieldArray[n].feature.setStyle(boundaryStyle);
313                    }
314                }
315            }
316        }
317
318    });
319
320
321    var map;
322
323    if (featureType == "field") {
324        map = new ol.Map({
325            controls: ol.control.defaults({
326                attribution: false,
327                zoom: false,
328            }),
329            target: 'result-map',
330            layers: [tiledRaster, streamJsonp, fieldJsonp],
331
332            view: new ol.View({
333                center: ol.proj.transform([-81.6695, 43.615], 'EPSG:4326', 'EPSG:3857'),
334                zoom: 13
335            })
336        });
337        $("#result-btn-group a").first().addClass('text-highlight');
338        layerSwitch = 1;
339    }
340
341    if (featureType == "subbasin") {
342        map = new ol.Map({
343            controls: ol.control.defaults({
344                attribution: false,
345                zoom: false,
346            }),
347            target: 'result-map',
348            layers: [tiledRaster, streamJsonp, subbasinJsonp],
349
350            view: new ol.View({
351                center: ol.proj.transform([-81.6695, 43.615], 'EPSG:4326', 'EPSG:3857'),
352                zoom: 13
353            })
354        });
355        $("#result-btn-group a").first().next().addClass('text-highlight');
356        layerSwitch = 0;
357    }
358
359
360
361    map.addControl(new ol.control.FullScreen());
362
363
364
365    $("#result-btn-group a").click(function(event) {
366        $(this).addClass('text-highlight');
367        $(this).siblings().removeClass('text-highlight');
368    });
369
370
371
372    $("#result-btn-group .layer-switch a").first().click(function(event) {
373        if (layerSwitch === 0) {
374            map.removeLayer(subbasinJsonp);
375            map.addLayer(fieldJsonp);
376        }
377
378        layerSwitch = 1;
379        var length = fieldArray.length;
380
381    });
382
383    $("#result-btn-group .layer-switch a").first().next().click(function(event) {
384        if (layerSwitch === 1) {
385            // addBoundary();
386            map.removeLayer(fieldJsonp);
387            map.addLayer(subbasinJsonp);
388        }
389        layerSwitch = 0;
390        var length = subbasinArray.length;
391
392    });
393
394
395    $("#result-btn-group .result-switch a").first().click(function(event) {
396        var a = map.getLayers().getArray()[2];
397        a.setStyle(styleFlowFunction2);
398    });
399    $("#result-btn-group .result-switch a").first().next().click(function(event) {
400        var a = map.getLayers().getArray()[2];
401        a.setStyle(styleSedimentFunction2);
402    });
403    $("#result-btn-group .result-switch a").first().next().next().click(function(event) {
404        var a = map.getLayers().getArray()[2];
405        a.setStyle(styleTpFunction2);
406    });
407    $("#result-btn-group .result-switch a").first().next().next().next().click(function(event) {
408        var a = map.getLayers().getArray()[2];
409        a.setStyle(styleTnFunction2);
410    });
411
412
413    // if (featureType == "subbasin") {
414    //     for (var m = 0; m < features.length; m++) {
415    //         for (var n = 0; n < subbasinArray.length; n++) {
416    //             if (features[m] == subbasinArray[n].id) {
417    //                 $("#result-table table tbody").append('<tr><th>ID</th><th>CC</th><th>CT</th><th>NM</th><th>WasCobs</th> </tr>');
418
419    //             }
420    //         }
421    //     }
422    // }
423
424    // var len = fieldArray.length;
425
426    // if (featureType == "field") {
427    //     for (var m = 0; m < features.length; m++) {
428    //         for (var n = 0; n < fieldArray.length; n++) {
429    //             if (features[m] == fieldArray[n].id) {
430    //                 $("#result-table table tbody").append('<tr><th>ID</th><th>CC</th><th>CT</th><th>NM</th><th>WasCobs</th> </tr>');
431
432    //             }
433    //         }
434    //     }
435    // }
436    // -----------------------------------------------------------------------------------------------------------
437
438
439    function styleSedimentFunction2(feature, resolution) {
440        var featureid = feature.getProperties().name;
441        var flag = 0;
442        for (i = 0; i < features.length; i++) {
443            var featuredf = features[i];
444            if (features[i] === feature.getProperties().name) {
445                var properties = feature.getProperties();
446                var level = feature.getProperties().sedimentlevel;
447                var value = feature.getProperties().sediment;
448                value = value.toFixed(2);
449                if (!level || !SeverityLevel[level]) {
450                    return [defaultStyle];
451                }
452                if (!styleCache[level]) {
453                    styleCache[level] = new ol.style.Style({
454                        fill: new ol.style.Fill({
455                            color: SeverityLevel[level]
456                        }),
457                        stroke: new ol.style.Stroke({
458                            color: "white",
459                            width: 1
460                        }),
461                        text: new ol.style.Text({
462                            // text: value,
463
464                            font: '12px Calibri,sans-serif',
465                            fill: new ol.style.Fill({ color: '#000' }),
466                            stroke: new ol.style.Stroke({
467                                color: '#fff',
468                                width: 2
469                            }),
470                            // get the text from the feature - `this` is ol.Feature
471                        })
472                    });
473                }
474                styleCache[level].getText().setText(value);
475                flag = 1;
476            } 
477        }
478
479        if (flag == 1){
480        	return [styleCache[level]];
481        }else{return [fieldStyle];}
482
483    }
484
485    function styleFlowFunction2(feature, resolution) {
486        var featureid = feature.getProperties().name;
487        var flag = 0;
488        for (i = 0; i < features.length; i++) {
489            var featuredf = features[i];
490            if (features[i] === feature.getProperties().name) {
491                var properties = feature.getProperties();
492                var level = feature.getProperties().flowlevel;
493                var value = feature.getProperties().flow;
494                value = value.toFixed(2);
495                if (!level || !SeverityLevel[level]) {
496                    return [defaultStyle];
497                }
498                if (!styleCache[level]) {
499                    styleCache[level] = new ol.style.Style({
500                        fill: new ol.style.Fill({
501                            color: SeverityLevel[level]
502                        }),
503                        stroke: new ol.style.Stroke({
504                            color: "white",
505                            width: 1
506                        }),
507                        text: new ol.style.Text({
508                            // text: value,
509
510                            font: '12px Calibri,sans-serif',
511                            fill: new ol.style.Fill({ color: '#000' }),
512                            stroke: new ol.style.Stroke({
513                                color: '#fff',
514                                width: 2
515                            }),
516                            // get the text from the feature - `this` is ol.Feature
517                        })
518                    });
519                }
520                styleCache[level].getText().setText(value);
521                flag = 1;
522            } 
523        }
524
525        if (flag == 1){
526        	return [styleCache[level]];
527        }else{return [fieldStyle];}
528
529    }
530
531        function styleTpFunction2(feature, resolution) {
532        var featureid = feature.getProperties().name;
533        var flag = 0;
534        for (i = 0; i < features.length; i++) {
535            var featuredf = features[i];
536            if (features[i] === feature.getProperties().name) {
537                var properties = feature.getProperties();
538                var level = feature.getProperties().tplevel;
539                var value = feature.getProperties().tp;
540                value = value.toFixed(2);
541                if (!level || !SeverityLevel[level]) {
542                    return [defaultStyle];
543                }
544                if (!styleCache[level]) {
545                    styleCache[level] = new ol.style.Style({
546                        fill: new ol.style.Fill({
547                            color: SeverityLevel[level]
548                        }),
549                        stroke: new ol.style.Stroke({
550                            color: "white",
551                            width: 1
552                        }),
553                        text: new ol.style.Text({
554                            // text: value,
555
556                            font: '12px Calibri,sans-serif',
557                            fill: new ol.style.Fill({ color: '#000' }),
558                            stroke: new ol.style.Stroke({
559                                color: '#fff',
560                                width: 2
561                            }),
562                            // get the text from the feature - `this` is ol.Feature
563                        })
564                    });
565                }
566                styleCache[level].getText().setText(value);
567                flag = 1;
568            } 
569        }
570
571        if (flag == 1){
572        	return [styleCache[level]];
573        }else{return [fieldStyle];}
574
575    }
576
577        function styleTnFunction2(feature, resolution) {
578        var featureid = feature.getProperties().name;
579        var flag = 0;
580        for (i = 0; i < features.length; i++) {
581            var featuredf = features[i];
582            if (features[i] === feature.getProperties().name) {
583                var properties = feature.getProperties();
584                var level = feature.getProperties().tnlevel;
585                var value = feature.getProperties().tn;
586                value = value.toFixed(2);
587                if (!level || !SeverityLevel[level]) {
588                    return [defaultStyle];
589                }
590                if (!styleCache[level]) {
591                    styleCache[level] = new ol.style.Style({
592                        fill: new ol.style.Fill({
593                            color: SeverityLevel[level]
594                        }),
595                        stroke: new ol.style.Stroke({
596                            color: "white",
597                            width: 1
598                        }),
599                        text: new ol.style.Text({
600                            // text: value,
601
602                            font: '12px Calibri,sans-serif',
603                            fill: new ol.style.Fill({ color: '#000' }),
604                            stroke: new ol.style.Stroke({
605                                color: '#fff',
606                                width: 2
607                            }),
608                            // get the text from the feature - `this` is ol.Feature
609                        })
610                    });
611                }
612                styleCache[level].getText().setText(value);
613                flag = 1;
614            } 
615        }
616
617        if (flag == 1){
618        	return [styleCache[level]];
619        }else{return [fieldStyle];}
620
621    }
622
623    var subbasinCompare = new ol.layer.Vector({
624        source: new ol.source.Vector({
625            url: '/assets/data/geojson/basincompareresult.json',
626            format: new ol.format.GeoJSON()
627        }),
628        style: subbasinStyle
629    });
630
631    subbasinCompare.getSource().on('change', function(event) {
632        var subbasinFeatures = subbasinCompare.getSource().getFeatures();
633        for (i = 0; i < subbasinFeatures.length; i++) {
634            var subbasin = new Subbasin();
635            subbasin.id = subbasinFeatures[i].getProperties().name;
636            subbasin.feature = subbasinFeatures[i];
637            subbasin.flow = subbasinFeatures[i].getProperties().flow;
638            subbasin.sediment = subbasinFeatures[i].getProperties().sediment;
639            subbasin.tp = subbasinFeatures[i].getProperties().tp;
640            subbasin.tn = subbasinFeatures[i].getProperties().tn;
641            subbasinArray2.push(subbasin);
642        }
643        if (featureType == "subbasin") {
644            for (var m = 0; m < features.length; m++) {
645                for (var n = 0; n < subbasinArray2.length; n++) {
646                    if (features[m] === subbasinArray2[n].id) {
647                        $("#compare-table table tbody").append('<tr><td>' + subbasinArray2[n].id + '</td><td>' + subbasinArray2[n].flow + '</td><td>' + subbasinArray2[n].sediment + '</td><td>' + subbasinArray2[n].tp + '</td><td>' + subbasinArray2[n].tn + '</td> </tr>');
648                    }
649                }
650            }
651
652        }
653
654    });
655
656
657    var fieldCompare = new ol.layer.Vector({
658        source: new ol.source.Vector({
659            url: '/assets/data/geojson/fieldcompareresult.json',
660            format: new ol.format.GeoJSON()
661        }),
662        style: fieldStyle
663    });
664
665    fieldCompare.getSource().on('change', function(event) {
666        var fieldFeatures = fieldCompare.getSource().getFeatures();
667        for (i = 0; i < fieldFeatures.length; i++) {
668            var field = new Field();
669            field.id = fieldFeatures[i].getProperties().name;
670            field.feature = fieldFeatures[i];
671            field.flow = fieldFeatures[i].getProperties().flow;
672            field.sediment = fieldFeatures[i].getProperties().sediment;
673            field.tp = fieldFeatures[i].getProperties().tp;
674            field.tn = fieldFeatures[i].getProperties().tn;
675            fieldArray2.push(field);
676        }
677        if (featureType === "field") {
678            for (var m = 0; m < features.length; m++) {
679                for (var n = 0; n < fieldArray2.length; n++) {
680                    if (features[m] === fieldArray2[n].id) {
681                        $("#compare-table table tbody").append('<tr><td>' + fieldArray2[n].id + '</td><td>' + fieldArray2[n].flow + '</td><td>' + fieldArray2[n].sediment + '</td><td>' + fieldArray2[n].tp + '</td><td>' + fieldArray2[n].tn + '</td> </tr>');
682                        // fieldArray[n].feature.setStyle(boundaryStyle);
683                    }
684                }
685            }
686        }
687
688    });
689
690
691    var map2;
692
693    if (featureType == "field") {
694        map2 = new ol.Map({
695            controls: ol.control.defaults({
696                attribution: false,
697                zoom: false,
698            }),
699            target: 'compare-map',
700            layers: [tiledRaster, streamJsonp, fieldCompare],
701
702            view: new ol.View({
703                center: ol.proj.transform([-81.6695, 43.615], 'EPSG:4326', 'EPSG:3857'),
704                zoom: 13
705            })
706        });
707    }
708
709    if (featureType == "subbasin") {
710        map2 = new ol.Map({
711            controls: ol.control.defaults({
712                attribution: false,
713                zoom: false,
714            }),
715            target: 'compare-map',
716            layers: [tiledRaster, streamJsonp, subbasinCompare],
717
718            view: new ol.View({
719                center: ol.proj.transform([-81.6695, 43.615], 'EPSG:4326', 'EPSG:3857'),
720                zoom: 13
721            })
722        });
723    }
724
725
726    map2.addControl(new ol.control.FullScreen());
727
728
729    $("#compare-btn-group a").first().addClass('text-highlight');
730
731    $("#compare-btn-group a").click(function(event) {
732        $(this).addClass('text-highlight');
733        $(this).siblings().removeClass('text-highlight');
734    });
735
736
737
738    $("#compare-btn-group .layer-switch a").first().click(function(event) {
739        if (layerSwitch2 === 0) {
740            map2.removeLayer(subbasinCompare);
741            map2.addLayer(fieldCompare);
742        }
743
744        layerSwitch2 = 1;
745    });
746
747    $("#compare-btn-group .layer-switch a").first().next().click(function(event) {
748        if (layerSwitch2 === 1) {
749            map2.removeLayer(fieldCompare);
750            map2.addLayer(subbasinCompare);
751        }
752        layerSwitch2 = 0;
753
754    });
755
756
757    $("#compare-btn-group .result-switch a").first().click(function(event) {
758        var a = map2.getLayers().getArray()[2];
759        a.setStyle(styleFlowFunction2);
760    });
761    $("#compare-btn-group .result-switch a").first().next().click(function(event) {
762        var a = map2.getLayers().getArray()[2];
763        a.setStyle(styleSedimentFunction2);
764    });
765    $("#compare-btn-group .result-switch a").first().next().next().click(function(event) {
766        var a = map2.getLayers().getArray()[2];
767        a.setStyle(styleTpFunction2);
768    });
769    $("#compare-btn-group .result-switch a").first().next().next().next().click(function(event) {
770        var a = map2.getLayers().getArray()[2];
771        a.setStyle(styleTnFunction2);
772    });
773
774});
775
Full Screen

get_properties_test.js

Source: get_properties_test.js Github

copy
1import { getProperties } from '../..';
2import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
3
4moduleFor(
5  'getProperties',
6  class extends AbstractTestCase {
7    ['@test can retrieve a hash of properties from an object via an argument list or array of property names'](
8      assert
9    ) {
10      let obj = {
11        firstName: 'Steve',
12        lastName: 'Jobs',
13        companyName: 'Apple, Inc.',
14      };
15
16      assert.deepEqual(getProperties(obj, 'firstName', 'lastName'), {
17        firstName: 'Steve',
18        lastName: 'Jobs',
19      });
20      assert.deepEqual(getProperties(obj, 'firstName', 'lastName'), {
21        firstName: 'Steve',
22        lastName: 'Jobs',
23      });
24      assert.deepEqual(getProperties(obj, 'lastName'), { lastName: 'Jobs' });
25      assert.deepEqual(getProperties(obj), {});
26      assert.deepEqual(getProperties(obj, ['firstName', 'lastName']), {
27        firstName: 'Steve',
28        lastName: 'Jobs',
29      });
30      assert.deepEqual(getProperties(obj, ['firstName']), {
31        firstName: 'Steve',
32      });
33      assert.deepEqual(getProperties(obj, []), {});
34    }
35  }
36);
37
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 Puppeteer 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)