Skip to content

Commit da6e8c2

Browse files
committed
Merge branch 'dev' of https://github.com/mmcc007/screenshots into dev
2 parents 4b5f9f9 + a2bccdf commit da6e8c2

File tree

1 file changed

+327
-0
lines changed

1 file changed

+327
-0
lines changed

test/screenshots_yaml.dart

Lines changed: 327 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,327 @@
1+
import 'dart:io';
2+
3+
import 'package:screenshots/config.dart';
4+
import 'package:screenshots/process_images.dart';
5+
import 'package:screenshots/screens.dart';
6+
import 'package:screenshots/image_magick.dart';
7+
import 'package:screenshots/resources.dart';
8+
import 'package:screenshots/screenshots.dart';
9+
import 'package:screenshots/utils.dart';
10+
import 'package:test/test.dart';
11+
import 'package:screenshots/fastlane.dart' as fastlane;
12+
13+
void main() {
14+
test('screen info for device: Nexus 5X', () async {
15+
final expected = {
16+
'resources': {
17+
'statusbar': 'resources/android/1080/statusbar.png',
18+
'navbar': 'resources/android/1080/navbar.png',
19+
'frame': 'resources/android/phones/Nexus_5X.png'
20+
},
21+
'destName': 'phone',
22+
'resize': '80%',
23+
'devices': ['Nexus 5X'],
24+
'offset': '-4-9',
25+
'size': '1080x1920'
26+
};
27+
final Screens screens = Screens();
28+
await Screens().init();
29+
Map screen = screens.screenProps('Nexus 5X');
30+
expect(screen, expected);
31+
});
32+
33+
test('screen info for device: iPhone X', () async {
34+
final expected = {
35+
'resources': {'frame': 'resources/ios/phones/Apple iPhone X Silver.png'},
36+
'resize': '75%',
37+
'devices': ['iPhone X'],
38+
'offset': '-0-0',
39+
'size': '2436×1125'
40+
};
41+
final Screens screens = Screens();
42+
await Screens().init();
43+
Map screen = screens.screenProps('iPhone X');
44+
expect(screen, expected);
45+
});
46+
47+
test('config info for app', () {
48+
final expected = {
49+
'tests': ['test_driver/main.dart'],
50+
'locales': ['en-US'],
51+
'frame': true,
52+
'devices': {
53+
'android': ['Nexus 5X'],
54+
'ios': ['iPhone 7 Plus']
55+
},
56+
'staging': '/tmp/screenshots'
57+
};
58+
59+
final Config config = Config('test/screenshots_test.yaml');
60+
Map appConfig = config.config;
61+
expect(appConfig, expected);
62+
});
63+
64+
test('overlay statusbar', () async {
65+
final Screens screens = Screens();
66+
await screens.init();
67+
Map screen = screens.screenProps('Nexus 6P');
68+
final Config config = Config('test/screenshots_test.yaml');
69+
Map appConfig = config.config;
70+
71+
// final screenshotPath = '/tmp/screenshots/test/0.png';
72+
// final statusbarResourcePath = 'resources/android/1080/statusbar.png';
73+
// final statusbarPath = '/tmp/statusbar.png';
74+
// final screenshotStatusbarPath = '/tmp/screenshots/test/0.png';
75+
76+
// final statusbarResourcePath = screen['statusbar'];
77+
78+
final Map resources = screen['resources'];
79+
await unpackImages(resources, '/tmp/screenshots');
80+
81+
final statusbarPath = '${appConfig['staging']}/${resources['statusbar']}';
82+
final screenshotPath = '${appConfig['staging']}/test/0.png';
83+
// final screenshotStatusbarPath =
84+
// '${appConfig['staging']}/test/statusbar-0.png';
85+
86+
final options = {
87+
'screenshotPath': screenshotPath,
88+
// 'statusbarResourcePath': statusbarResourcePath,
89+
'statusbarPath': statusbarPath,
90+
// 'screenshotStatusbarPath': screenshotStatusbarPath,
91+
};
92+
print('options=$options');
93+
await imagemagick('overlay', options);
94+
});
95+
96+
test('unpack screen resource images', () async {
97+
final Screens screens = Screens();
98+
await screens.init();
99+
// Map screen = screens.screen(screensInfo, 'Nexus 5X');
100+
Map screen = screens.screenProps('iPhone 7 Plus');
101+
final Config config = Config('test/screenshots_test.yaml');
102+
Map appConfig = config.config;
103+
104+
final staging = appConfig['staging'];
105+
106+
final Map screenResources = screen['resources'];
107+
// print('resources=$resources');
108+
// List screenResources = [];
109+
// resources.forEach((k, resource) {
110+
// screenResources.add(resource);
111+
// });
112+
print('screenResources=$screenResources');
113+
114+
await unpackImages(screenResources, staging);
115+
});
116+
117+
test('append navbar', () async {
118+
final Screens screens = Screens();
119+
await screens.init();
120+
Map screen = screens.screenProps('Nexus 6P');
121+
final Config config = Config('test/screenshots_test.yaml');
122+
Map appConfig = config.config;
123+
124+
final Map resources = screen['resources'];
125+
await unpackImages(resources, '/tmp/screenshots');
126+
127+
final screenshotNavbarPath =
128+
'${appConfig['staging']}/${resources['navbar']}';
129+
final screenshotPath = '${appConfig['staging']}/test/0.png';
130+
131+
final options = {
132+
'screenshotPath': screenshotPath,
133+
'screenshotNavbarPath': screenshotNavbarPath,
134+
};
135+
print('options=$options');
136+
await imagemagick('append', options);
137+
});
138+
139+
test('frame screenshot', () async {
140+
final Screens screens = Screens();
141+
await screens.init();
142+
Map screen = screens.screenProps('Nexus 6P');
143+
final Config config = Config('test/screenshots_test.yaml');
144+
Map appConfig = config.config;
145+
146+
final Map resources = screen['resources'];
147+
await unpackImages(resources, '/tmp/screenshots');
148+
149+
final framePath = appConfig['staging'] + '/' + resources['frame'];
150+
final size = screen['size'];
151+
final resize = screen['resize'];
152+
final offset = screen['offset'];
153+
final screenshotPath = '${appConfig['staging']}/test/0.png';
154+
155+
final options = {
156+
'framePath': framePath,
157+
'size': size,
158+
'resize': resize,
159+
'offset': offset,
160+
'screenshotPath': screenshotPath,
161+
'backgroundColor': kDefaultAndroidBackground,
162+
};
163+
print('options=$options');
164+
await imagemagick('frame', options);
165+
});
166+
167+
test('parse xcrun simctl list devices', () {
168+
Map _simulators = simulatorsx();
169+
print('simulators=$_simulators');
170+
171+
print('iPhone X info: ' + _simulators['iPhone X'].toString());
172+
173+
// print('first match:' + regExp.firstMatch(screens).toString());
174+
});
175+
176+
test('parse json xcrun simctl list devices', () {
177+
Map iosDevices = getIosDevices();
178+
179+
// Map _simulators = simulators2();
180+
// print('simulators=$_simulators');
181+
//
182+
print('iPhone 7 Plus info: ' + iosDevices['iPhone 7 Plus'].toString());
183+
// print('iPhone X info: ' + iosDevices['iPhone X'].toString());
184+
// print('first match:' + regExp.firstMatch(screens).toString());
185+
});
186+
187+
test('get highest and available version of ios device', () {
188+
Map iosDevices = getIosDevices();
189+
final deviceName = 'iPhone 7 Plus';
190+
// final Map iOSVersions = iosDevices['iPhone 7 Plus'];
191+
// print('iOSVersions=$iOSVersions');
192+
//
193+
// // sort keys in iOS version order (just in case)
194+
// final keys = iOSVersions.keys.toList();
195+
// print('keys=$keys');
196+
// keys.sort((v1, v2) {
197+
// return v1.compareTo(v2);
198+
// });
199+
// print('keys=$keys');
200+
// final iOSVersionName = keys.last;
201+
// final Map highestDevice = iosDevices[deviceName][iOSVersionName][0];
202+
final highestDevice = getHighestIosDevice(iosDevices, deviceName);
203+
print('highestDevice=$highestDevice');
204+
});
205+
206+
test('read resource and write to path', () async {
207+
// print(await sampleTxt());
208+
// print(await sampleImage());
209+
//// print(await image('resources/sample.png'));
210+
// writeImage(await sampleImage(), '/tmp/sample.png');
211+
final resources = [
212+
'resources/android/1080/statusbar.png',
213+
'resources/android/1080/navbar.png',
214+
'resources/android/phones/Nexus_5X.png'
215+
];
216+
final dest = '/tmp';
217+
for (String resource in resources)
218+
writeImage(await readResourceImage(resource), '$dest/$resource');
219+
});
220+
221+
test('unpack images', () async {
222+
final resources = {
223+
'A': 'resources/android/1080/statusbar.png',
224+
'B': 'resources/android/1080/navbar.png',
225+
'C': 'resources/android/phones/Nexus_5X.png'
226+
};
227+
final dest = '/tmp';
228+
await unpackImages(resources, dest);
229+
});
230+
231+
test('unpack script', () async {
232+
await unpackScript('/tmp', 'resources/script/android-wait-for-emulator');
233+
});
234+
235+
test('add prefix to files in directory', () async {
236+
await prefixFilesInDir('/tmp/screenshots/test', 'my_prefix');
237+
});
238+
239+
test('validate config file', () async {
240+
final Screens screens = Screens();
241+
await screens.init();
242+
final Config config = Config('test/screenshots_test.yaml');
243+
expect(await config.validate(screens), true);
244+
});
245+
246+
test('config guide', () async {
247+
final Screens screens = Screens();
248+
await screens.init();
249+
final Config config = Config('test/screenshots_test.yaml');
250+
config.configGuide(screens);
251+
});
252+
253+
test('rooted emulator', () {
254+
final result = cmd('adb', ['root']);
255+
print(result);
256+
expect(result, 'adbd cannot run as root in production builds\n');
257+
});
258+
259+
test('map device name to emulator', () {
260+
final _emulators = emulators();
261+
print(_emulators);
262+
final emulator =
263+
_emulators.firstWhere((emulator) => emulator.contains('Nexus_5X'));
264+
expect(emulator, 'Nexus_5X_API_27');
265+
});
266+
267+
test('change android locale', () {
268+
// emulator('Nexus 6P', true, '/tmp/screenshots', 'fr-CA');
269+
emulator('Nexus 6P', true, '/tmp/screenshots', 'en-US');
270+
});
271+
272+
test('move files', () async {
273+
final fileName = 'filename';
274+
final srcDir = '/tmp/tmp1/multiple/levels/deep';
275+
final dstDir = '/tmp/tmp2/more/levels/deep';
276+
277+
await File('$srcDir/$fileName').create(recursive: true);
278+
moveFiles(srcDir, dstDir);
279+
expect(await File(dstDir + '/' + fileName).exists(), true);
280+
});
281+
282+
test('start simulator', () {
283+
simulator('iPhone X', true, '/tmp/screenshots');
284+
// simulator('iPhone X', true, '/tmp/screenshots', 'fr-CA');
285+
});
286+
287+
test('stream output from command', () async {
288+
await streamCmd('ls', ['-la']);
289+
stdout.write('finished\n\n');
290+
// print('finished\n');
291+
// await stdout.flush();
292+
// await stdout.close();
293+
// await stdout.done;
294+
await streamCmd('ls', ['-33']);
295+
});
296+
297+
test('clear all destination directories on init', () async {
298+
final Screens screens = Screens();
299+
await screens.init();
300+
final Config config = Config('test/screenshots_test.yaml');
301+
await fastlane.clearFastlaneDirs(config.config, screens);
302+
});
303+
304+
test('start emulator on travis', () async {
305+
final androidHome = Platform.environment['ANDROID_HOME'];
306+
final emulatorName = 'Nexus_6P_API_27';
307+
await streamCmd(
308+
'$androidHome/emulator/emulator',
309+
[
310+
'-avd',
311+
emulatorName,
312+
'-no-audio',
313+
'-no-window',
314+
'-no-snapshot',
315+
'-gpu',
316+
'swiftshader',
317+
],
318+
ProcessStartMode.detached);
319+
});
320+
321+
test('check for no running emulators, simulators or devices', () {
322+
if (cmd('flutter', ['devices'], '.', true).contains('No devices detected.'))
323+
print('nothing running');
324+
else
325+
print('something running');
326+
});
327+
}

0 commit comments

Comments
 (0)