• Home
  • Insight
  • Blog
  • Business
  • Entertainment
  • Health
  • Politics
  • Shop
    • Gift Shop
    • Value Shop
    • Store
    • Bargain Shop
    • Discount
  • Sports
  • Tech
  • Travel
  • USA
  • Video
  • World
    • Asia
    • Africa
    • South America
    • North America
    • Europe
    • Oceania
Monday, November 16, 2026
No Result
View All Result
Subscribe Now
  • Home
  • Insight
  • Blog
  • Business
  • Entertainment
  • Health
  • Politics
  • Shop
    • Gift Shop
    • Value Shop
    • Store
    • Bargain Shop
    • Discount
  • Sports
  • Tech
  • Travel
  • USA
    Stranded in Conflict: Palestinians Navigate the Tenuous Balance of War and Peace Amid Ceasefire Efforts

    Stranded in Conflict: Palestinians Navigate the Tenuous Balance of War and Peace Amid Ceasefire Efforts

    Trump Administration Revokes Pay Increase for Head Start Educators

    Trump Administration Revokes Pay Increase for Head Start Educators

    Unexpected Triumph: Gay Candidates Achieve Unforeseen Victories in Challenging Races

    Unexpected Triumph: Gay Candidates Achieve Unforeseen Victories in Challenging Races

    Microsoft Outlook Experiences Prolonged Outage Affecting Users Nationwide

    Microsoft Outlook Experiences Prolonged Outage Affecting Users Nationwide

    Gunfire Erupts in D.C.: Authorities Search for Suspect Amid Rising Concerns Over Public Safety

    Gunfire Erupts in D.C.: Authorities Search for Suspect Amid Rising Concerns Over Public Safety

    LAUSD Takes Strong Action Against Hate Speech Following Racial Slur Incidents

    LAUSD Takes Strong Action Against Hate Speech Following Racial Slur Incidents

    Beloved Former Los Angeles Times Columnist Steve Harvey Passes Away at 80

    Beloved Former Los Angeles Times Columnist Steve Harvey Passes Away at 80

    Exploring Diversity: ‘Ten Lives’ Showcases the Varied Economic Journeys of Americans

    Exploring Diversity: ‘Ten Lives’ Showcases the Varied Economic Journeys of Americans

    Philadelphia Eagles Facing Turmoil as Coach Nick Sirianni Addresses Controversy Over Gesture to Fans

    Philadelphia Eagles Facing Turmoil as Coach Nick Sirianni Addresses Controversy Over Gesture to Fans

  • Video
  • World
    • Asia
    • Africa
    • South America
    • North America
    • Europe
    • Oceania
The Insight Post
  • Home
  • Insight
  • Blog
  • Business
  • Entertainment
  • Health
  • Politics
  • Shop
    • Gift Shop
    • Value Shop
    • Store
    • Bargain Shop
    • Discount
  • Sports
  • Tech
  • Travel
  • USA
    Stranded in Conflict: Palestinians Navigate the Tenuous Balance of War and Peace Amid Ceasefire Efforts

    Stranded in Conflict: Palestinians Navigate the Tenuous Balance of War and Peace Amid Ceasefire Efforts

    Trump Administration Revokes Pay Increase for Head Start Educators

    Trump Administration Revokes Pay Increase for Head Start Educators

    Unexpected Triumph: Gay Candidates Achieve Unforeseen Victories in Challenging Races

    Unexpected Triumph: Gay Candidates Achieve Unforeseen Victories in Challenging Races

    Microsoft Outlook Experiences Prolonged Outage Affecting Users Nationwide

    Microsoft Outlook Experiences Prolonged Outage Affecting Users Nationwide

    Gunfire Erupts in D.C.: Authorities Search for Suspect Amid Rising Concerns Over Public Safety

    Gunfire Erupts in D.C.: Authorities Search for Suspect Amid Rising Concerns Over Public Safety

    LAUSD Takes Strong Action Against Hate Speech Following Racial Slur Incidents

    LAUSD Takes Strong Action Against Hate Speech Following Racial Slur Incidents

    Beloved Former Los Angeles Times Columnist Steve Harvey Passes Away at 80

    Beloved Former Los Angeles Times Columnist Steve Harvey Passes Away at 80

    Exploring Diversity: ‘Ten Lives’ Showcases the Varied Economic Journeys of Americans

    Exploring Diversity: ‘Ten Lives’ Showcases the Varied Economic Journeys of Americans

    Philadelphia Eagles Facing Turmoil as Coach Nick Sirianni Addresses Controversy Over Gesture to Fans

    Philadelphia Eagles Facing Turmoil as Coach Nick Sirianni Addresses Controversy Over Gesture to Fans

  • Video
  • World
    • Asia
    • Africa
    • South America
    • North America
    • Europe
    • Oceania
No Result
View All Result
No Result
View All Result
Home Mobile

How to add screenshots to your automated tests on Codemagic

by Theinsightpost
August 13, 2022
in Mobile
0 0
0
How to add screenshots to your automated tests on Codemagic


Written by Neevash Ramdial

Picture this, you’re running UI tests on your Flutter application when it dawns on you,

“Wouldn’t it be cool if I can capture the state of my UI at various stages during the testing process?”.

Click to tweet

If that person is you or you’re intrigued, you’ve found the right place. In this article, we are going to look at configuring and capturing screenshots on Codemagic while running Flutter Driver tests.

Prerequisites

For those would like to follow along with this article, there are two things you need to have:


0: Project Configuration ⚒️

For simplicity, I am going to use the default “counter” Flutter project. Since the focus of this article is taking screenshots on Codemagic, I am not going to cover writing integration tests. If you’d like to learn more about writing integration tests, please see this article.
To create a new Flutter project run:

The command above would generate the following project files:

1: Dependencies ?

Before we can move into the code, we first need to add a dependency to the project. This package will allow us to capture screenshots while testing.
Navigate to pub.dev and search for screenshots. Once you’ve found the package, add it to your project.
Add “screenshots” to pubspec.yaml :

dependencies:
  screenshots: ^2.1.1

Once added, run flutter packages get to update the project packages.

2: Screenshot Configuration ⚒️

With our package installed, a configuration file for capturing screenshots needs to be created.
Let’s start by creating the file screenshots.yaml in the project root directory.

tests:
  - test_driver/app.dart
staging: /Users/builder/exported_artefacts
devices:
  ios:
    iPhone XS Max:
      frame: false
      orientation: Portrait

At first glance, you might be a little confused but fear not:

  • tests - List of the test to execute
  • staging - Temporary location for storing captured screenshots
  • devices - Controls the list of frames and platforms to capture screenshots. Devices can be broken up into separate configuration files however we will not be looking at those in this article.
  • archive- Saves screenshots for local use.

Note: In the example above, we use the absolute path of the export folder, you can use Codemagic’s environment variable if you desire.

3: The Code ?

Integrating screenshots is a very easy process. To get started, we need to create the directory test_driver folder in our project root.

In our driver folder, two files need to be created, app.dart and app_test.dart. Two files are necessary since unlike other tests, Flutter integration tests are executed in different processes.

Our app.dart file contains an instrumented version of our app. In this file, we enable Flutter driver then start the execution of the tests.

To get started, paste the following code in app.dart:

import 'package:codemagic/main.dart' as app;
import 'package:flutter_driver/driver_extension.dart';
main() {
  enableFlutterDriverExtension();
  app.main();
}

Next, we need to modify our app and add a key to our Text widget. This is necessary for us to “find” and examine our widget from our test script.
Make the following modifications to the existing text widget:

From:

Text(
  '$_counter',
   style: Theme.of(context).textTheme.headline4,
),

To:

Text(
  '$_counter',
   key: ValueKey('count-value'),
   style: Theme.of(context).textTheme.headline4,
),

Great! We’re almost finished, now it’s time to write our test.

void main() {
  FlutterDriver driver;
final buttonFinder = find.byType('FloatingActionButton');
final textFinder = find.byValueKey('count-value');

group('Full body test', () {

    setUpAll(
      () async {
        driver = await FlutterDriver.connect();
      },
    );
test(
      'Increment counter',
      () async {
        await driver.tap(buttonFinder);
        expect(await driver.getText(textFinder), "1");
      }),
    );
tearDownAll(() {
      if (driver != null) {
        driver.close();
      }
    });
  });
}

The snippet about is a snippet driver file for incrementing the app counter. Let’s breakdown the functions in our file.

We create two finders for locating and referencing the widgets we will be interacting with this test. Notice for the textFinder method, byValueKey is used to locate our text instance. This is necessary since our sample app contains more than one Text widget. The button finder, on the other hand, uses byType since there is only a single FloatingActionButton in our app.

Next, we have the methods setUpAll and tearDownAll. Both methods are respectively executed before and after the test us run. These methods are used to connect our driver and execute any setup code that may be necessary for running the test.

Finally, the test function. As the name implies, this is where you write your test code, typically a test would consist of some instructions for manipulating the app’s UI followed by expectations of the new UI state. In our example, the driver simulates a tap on our FloatingActionButton then uses the expect keyword to validate our new UI state.

To run this test, execute the following command:

flutter drive -t test_driver/app.dart

If all goes to plan, you will be greeted with the message “All test passed”.

4: ?

Time for the final piece of the puzzle, capturing the screenshot.

Open app_test.dart and add the following import:

import 'package:screenshots/screenshots.dart';

Next, create an instance of a Config(). Screenshots uses this config to save and manage screenshots. We can use the default config for now.

In the last step, we need to call the screenshot function in our code to capture our screenshot. The method requires three arguments, the current Flutter Driver instance, the config, and a name.

await screenshot(driver, config, 'testing');

Note: For local testing, change the staging and archive screenshot path to a place on your local machine. Since I am on Mac, I use ~/ since it is easy to find

Fantastic! You’ve just enabled screenshots for Flutter driver tests. Go ahead and run the test. Once completed, you will notice a new directory on your computer containing the screenshots.

5: Next Steps 

With the project setup and code finished, go ahead and push your project to Git .

Go to https://codemagic.io/apps, select your application and hit the settings “cog” icon to change its configuration.

Expand the test section of the Codemagic project settings and enable “Enable Flutter Driver tests”.

Finally, modify the “Flutter drive arguments” section to target app.dart instead of main.dart. If you are also building your project, please select channel “dev” since this was used during testing.

Drumroll please…. Hit the “start new build” button on the top of the page to build your project. After a few minutes, you will notice a new zip file on the left pane.

Voila! Downloading and extracting the folder will contain our screenshot.

In Closing

Congratulations! You’ve successfully added screenshots to your automated test. Feel free to experiment and expand on what you’ve learned in this tutorial.

If you enjoyed this article, checkout some of the other articles below:


Nash writes code for computers and articles for humans. Born and raised in Trinidad, he fell in love with coding at the age of fourteen and has worked in both web and mobile development ever since. Nash is the Lead Editor of Flutter Community on Medium; co-host of the weekly, international web conference “HumpDayQandA” and an Administrator of the Flutter Study Group (FSG).
Make sure you follow Nash on Twitter @Nash0x7e2





Source link

ShareTweetSend
Previous Post

Fear as Kenya Electoral Commission Official Goes Missing

Next Post

Children with disabilities disproportionately impacted by war in Ukraine  – europeantimes.news

Related News

Unlocking Potential: Exploring the FDE Model in Enterprise AI Solutions
Mobile

Unlocking Potential: Exploring the FDE Model in Enterprise AI Solutions

November 14, 2026
Unlocking the Scoop: Upcoming Sale Dates, Price Highlights, and Previous Bargains
Mobile

Unlocking the Scoop: Upcoming Sale Dates, Price Highlights, and Previous Bargains

November 14, 2026
Unlocking Website Security: The Marketbyte Edge in Open Source Solutions
Mobile

Unlocking Website Security: The Marketbyte Edge in Open Source Solutions

November 13, 2026
Uncovering the Best Solutions for Your Mobile Risk Concerns
Mobile

Uncovering the Best Solutions for Your Mobile Risk Concerns

November 12, 2026
Next Post
Children with disabilities disproportionately impacted by war in Ukraine  – europeantimes.news

Children with disabilities disproportionately impacted by war in Ukraine  – europeantimes.news

Discussion about this post

Subscribe To Our Newsletters

    Customer Support


    1251 Wilcrest Drive
    Houston, Texas
    77042 USA
    Call-832.795.1420
    e-mail – news@theinsightpost.com

    Subscribe To Our Newsletters

      Categories

      • Africa
      • Africa-East
      • African Sports
      • American Sports
      • Arts
      • Asia
      • Australia
      • Business
      • Business Asia
      • Business- Africa
      • Canada
      • Defense
      • Education
      • Egypt
      • Energy
      • Entertainment
      • Europe
      • European Soccer
      • Finance
      • Germany
      • Ghana
      • Health
      • Insight
      • International
      • Investing
      • Japan
      • Latest Headlines
      • Life & Living
      • Markets
      • Mobile
      • Movies
      • New Zealand
      • Nigeria
      • Politics
      • Scholarships
      • Science
      • South Africa
      • South America
      • Sports
      • Tech
      • Travel
      • Travel-Africa
      • UK
      • USA
      • Weather
      • World
      No Result
      View All Result

      Recent News

      Gators Shock Wildcats 21-14 in Thrilling Upset Amid Rollercoaster Season

      Gators Shock Wildcats 21-14 in Thrilling Upset Amid Rollercoaster Season

      November 15, 2026
      Government Announces Historic  Billion Investment in Energy Infrastructure Development

      Government Announces Historic $2 Billion Investment in Energy Infrastructure Development

      November 15, 2026
      Notre Dame Postgame Insights: Dive into Superchats with Westwood One Sports

      Notre Dame Postgame Insights: Dive into Superchats with Westwood One Sports

      November 15, 2026
      Transform Your Laptop Setup with These 5 Affordable Accessories

      Transform Your Laptop Setup with These 5 Affordable Accessories

      November 15, 2026
      • Home
      • Advertise With Us
      • About Us
      • Corporate
      • Consumer Rewards
      • Forum
      • Privacy Policy
      • Social Trends

      Theinsightpost ©2026 | All Rights Reserved. Theinsightpost is an Elnegy LLC company, registered in Texas, USA

      Welcome Back!

      Login to your account below

      Forgotten Password?

      Retrieve your password

      Please enter your username or email address to reset your password.

      Log In

      Add New Playlist

      We are using cookies to give you the best experience on our website.

      You can find out more about which cookies we are using or switch them off in .

      No Result
      View All Result
      • Home
      • Insight
      • Blog
      • Business
      • Entertainment
      • Health
      • Politics
      • Shop
        • Gift Shop
        • Value Shop
        • Store
        • Bargain Shop
        • Discount
      • Sports
      • Tech
      • Travel
      • USA
      • Video
      • World
        • Asia
        • Africa
        • South America
        • North America
        • Europe
        • Oceania

      Theinsightpost ©2026 | All Rights Reserved. Theinsightpost is an Elnegy LLC company, registered in Texas, USA

      The Insight Post
      Powered by  GDPR Cookie Compliance
      Privacy Overview

      This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

      Strictly Necessary Cookies

      Strictly Necessary Cookie should be enabled at all times so that we can save your preferences for cookie settings.

      Cookie Policy

      More information about our Cookie Policy