Last active
June 14, 2020 21:11
-
-
Save ookami-kb/96d332a67de17da56e729c83f802b6c4 to your computer and use it in GitHub Desktop.
flutter-azure-ci
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
export PATH=$BUILD_SOURCESDIRECTORY/flutter/bin:$BUILD_SOURCESDIRECTORY/flutter/bin/cache/dart-sdk/bin:$PATH | |
# All scripts will be placed here | |
"$@" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
install_flutter() { | |
git clone -b stable https://github.com/flutter/flutter.git | |
flutter precache | |
yes | $ANDROID_HOME/tools/bin/sdkmanager --licenses | |
flutter doctor | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
launch_avd() { | |
echo "Installing SDK" | |
$ANDROID_HOME/tools/bin/sdkmanager --install 'system-images;android-29;default;x86' | |
echo "Creating emulator" | |
$ANDROID_HOME/tools/bin/avdmanager create avd -n "pixel" --device "pixel" -k "system-images;android-29;default;x86" | |
echo "Starting emulator" | |
$ANDROID_HOME/emulator/emulator -avd "pixel" -no-snapshot & | |
$ANDROID_HOME/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed | tr -d '\r') ]]; do sleep 1; done; input keyevent 82' | |
echo "Emulator started" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
start_recording() { | |
# Each video is 3 minutes max, so 5 videos will give us up to 15 minutes, | |
# should be enough for test | |
$ANDROID_HOME/platform-tools/adb shell mkdir /sdcard/video | |
$ANDROID_HOME/platform-tools/adb shell screenrecord /sdcard/video/1.mp4 | |
$ANDROID_HOME/platform-tools/adb shell screenrecord /sdcard/video/2.mp4 | |
$ANDROID_HOME/platform-tools/adb shell screenrecord /sdcard/video/3.mp4 | |
$ANDROID_HOME/platform-tools/adb shell screenrecord /sdcard/video/4.mp4 | |
$ANDROID_HOME/platform-tools/adb shell screenrecord /sdcard/video/5.mp4 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
flutter_test() { | |
flutter packages get | |
flutter packages pub run build_runner build | |
flutter test | |
launch_avd | |
start_recording & | |
flutter drive --target=test_driver/app.dart | |
pkill -f screenrecord || true | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pull_video() { | |
$ANDROID_HOME/platform-tools/adb pull /sdcard/video $BUILD_SOURCESDIRECTORY/screenshots | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trigger: none | |
pr: | |
- master | |
jobs: | |
- job: Test | |
timeoutInMinutes: 20 | |
pool: | |
vmImage: 'macOS-latest' | |
steps: | |
- script: pipelines/scripts.sh install_flutter | |
displayName: Install Flutter | |
- script: pipelines/scripts.sh flutter_test | |
displayName: Test app | |
- script: ../pipelines/scripts.sh pull_video | |
displayName: Pull screen video record | |
condition: always() | |
- task: PublishBuildArtifacts@1 | |
displayName: Publish screenshots | |
condition: always() | |
inputs: | |
pathtoPublish: '$(System.DefaultWorkingDirectory)/screenshots/' | |
artifactName: screenshots |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:commander/main.dart' as app; | |
import 'package:flutter_driver/driver_extension.dart'; | |
void main() { | |
enableFlutterDriverExtension(); | |
app.main(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:io'; | |
import 'package:flutter_driver/flutter_driver.dart'; | |
import 'package:test/test.dart'; | |
import 'app_test_resources.dart'; | |
void main() { | |
group('Smoke tests', () { | |
FlutterDriver driver; | |
// Connect to the Flutter driver before running any tests. | |
setUpAll(() async { | |
driver = await FlutterDriver.connect(); | |
await Directory('screenshots').create(); | |
}); | |
// Close the connection to the driver after the tests have completed. | |
tearDownAll(() async { | |
if (driver != null) { | |
await driver.close(); | |
} | |
}); | |
test('Commander Walkthrough', () async { | |
await loginToCommander(driver); | |
await goToMessages(driver); | |
await goToTasks(driver); | |
await goToProfile(driver); | |
await goToRooms(driver); | |
}, timeout: const Timeout(Duration(minutes: 1))); | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Future<void> goToRooms(FlutterDriver driver) async { | |
await driver.tap(find.byValueKey('rooms')); | |
await driver.assertElementPresent('sliverList'); | |
await driver.assertElementPresent('floorHeader'); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:io'; | |
import 'package:flutter_driver/flutter_driver.dart'; | |
extension DriverExt on FlutterDriver { | |
Future<void> saveScreenshot() async { | |
final path = 'screenshots/' | |
'${DateTime.now().toIso8601String().replaceAll(':', '-')}' | |
'.png'; | |
final List<int> pixels = await screenshot(); | |
final file = File(path); | |
await file.writeAsBytes(pixels); | |
} | |
Future<void> assertElementPresent( | |
String valueKey, { | |
Duration timeout = const Duration(seconds: 5), | |
}) async { | |
try { | |
return await waitFor(find.byValueKey(valueKey), timeout: timeout); | |
// ignore: avoid_catching_errors | |
} on DriverError catch (_) { | |
await saveScreenshot(); | |
rethrow; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment