Giter Club home page Giter Club logo

fastlane-plugin-ionic_integration's Introduction

ionic_integration plugin

fastlane Plugin Badge

Getting Started

This project is a fastlane plugin. To get started with fastlane-plugin-ionic_integration, add it to your project by running:

fastlane add_plugin ionic_integration

About ionic_integration

Integrating Fastlane with Ionic Generated Projects

Fastlane is an awesome application. However the assumption is that you are in control of the iOS or Android projects while using it. When developing in Ionic (or Cordova), the relevant platform projects are created for you by Ionic. For example ionic platform add ios

This poses a problem when attempting to automate the build process. We do not want to put the generated projects under source control, however we would like to be able to link it into fastlane??

This plugin will let you generate a sample UI Test group for generating snapshots the fastlane way. But it stores the UI Unit tests in your fastlane folder so that you can commit only these to version control. The plugin, will then retrofit these tests into the Ionic/Cordova generated projects.

There are two actions (so far) ionic_ios_config_snapshot get's you started with a sample UI Test configuration (and saves it to fastlane/ionic/config/ios/ui-tests). The UI Unit Tests are linked into any existing XCode project generated by Ionic.

ionic_ios_snapshot Scans the fastlane/ionic/config/ios/ui-tests folder for sub folders that represent UI Test Schemes (each folder is a scheme). It retrofits each UI Test scheme into the XCode projects generated by Ionic. This should be executed before you perform fastlane snapshot.

NOTE: At the moment this works for Xcode 8+. If anyone out there is interested in contributing, it would be great to support XCode 7 and (ideally) be able to do a similar thing for Android generated projects.

Example

Check out the example Fastfile to see how to use this plugin. Try it by cloning the repo, running fastlane install_plugins and bundle exec fastlane test.

Before You Get Started

Xcode 8+ uses Team Id and Code Signing Identities. In order to get Ionic/Cordova projects to generate the correct values you can include a build.json file at the root of your iconic project. This file can then be supplied to the ionic build like so (using a build script you create):

ionic platform add ios 

ionic build ios --release --buildConfig=build.json

The json file is strutured like this:

{
  "ios": {
    "debug": {
      "developmentTeam": "XXXXXXXX",
      "codeSignIdentity": "iPhone Developer",
      "packageType": "development"
    },

    "release": {
      "developmentTeam": "XXXXXXX",
      "codeSignIdentity": "iPhone Developer",
      "packageType": "app-store"
    }
  }
}

Please refer to the Cordova iOS Guide for more details.

Generating a Sample UI Test Scheme

To get started with a sample UI Unit Test Scheme, issue the following command:

fastlane run ionic_ios_config_snapshot ionic_scheme_name:"[YOUR CHOSEN NAME]"

For example: fastlane run ionic_ios_config_snapshot ionic_scheme_name:"ionic-screen-shots"

You can also specify which xcode project to use and minimum iOS version using ionic_ios_xcode_path and ionic_min_target_ios options respectively. The xcode project will be autodetected as the project (.xcodeproj) associated with the workspace (.xcworkspace) in platforms/ios folder generated by ionic/cordova.

The command above will create a folder fastlane/ionic/config/ios/ui-tests/ionic-screen-shots

In this folder will be the standard test files that you would expect for a UI Unit Test, Info.plist, Fastlane SWIFT file and a sample Unit Test ui-snapshots.swift

ionic_ios_config_snapshot also executes the ionic_config_snapshot action to retrofit this unit test configuration into any existing XCode Project

When this is done. The sample will be linked into your generated project. In the above example, a UI Test scheme will be created in fastlane/ionic/config/ios/ui-tests/ionic-screen-shots. The files in this folder are linked absolutely into Xcode, that is Xcode refers directly to these files (they are not copied over to Xcode)

If you open up Xcode and open the file 'ionic-screen-shots/ui-snapshots.swift' you will see something like this:

    func testSnapshots() {

        //
        // Place your own tests here. This is a starter example to get you going..
        //
        snapshot("app-launch")
        
        // XCUIApplication().buttons["Your Button Name"].tap()
        
        // snapshot("after-button-pressed")
                
    }

In the XCode UI, select the scheme 'ionic-screen-shots' and click into the method 'testSnapshots()' (after the first snapshot).

Select UI Scheme

You can now click on the 'Record UI Test' (Red Circle Icon).

Record UI Test

This will open the simulator and you can click around in your application. XCode will record, each interaction within the testSnapshots() method.

When you are done, you can save everthing and it will save those interactions into the fastlane/ionic/config/ios/ui-tests/ui-snapshots.swift.

You can now add fastlane snapshot("decription") where you like.

This whole operation only needs to be done once (or if you want to add more screenshots later).

The UI Test files can be added to your source control and they will be retrofitted into any future generated Ionic projects by the ionic_ios_snapshot action.

Retrofitting UI Test Scheme via Fastlane

After you have created your first UI Test Scheme using ionic_ios_config_snapshot, you will now need to ensure the unit tests are retrofitted into the xcode project generated by ionic/cordova.

The ionic_ios_snapshot action can be executed before any other lane in your Fastfile by placing it in a before_all block.

The parameters for ionic_ios_snapshot action will mostly be autodetected. It attempts to pick the xcode project by looking in platforms/ios folder. The team_id parameter is automatically set if it is specified in your fastlane Appfile. The bundle_id is set automatically if the package_name parameter is set in your fastlane Appfile. All these parameters can be overridden by specifying them in the call to the action. To see what has been automatically picked up for your configuration, use fastlane action ionic_ios_snapshot

ionic_ios_snapshot lists all the subfolders in the folder fastlane/ionic/config/ios/ui-tests. It then creates a UI Test Target and Scheme based on the name of the subfolder, in the example above, this would be a single target/scheme called ionic-snap-shots. It effectively 'retrofits' the UI tests into the iOS xcode project for you.

After ionic_ios_snapshot is executed, you can now specify any of the schemes you generated to be used in fastlane snapshot action, using the 'scheme' parameter.

Your fully automated Fastlane file can now look like this:

platform :ios do

  before_all do
    #
    # This will retrofit any existing schemes in fastlane/ionic/config/ios/ui-tests/
    #
    ionic_ios_snapshot(
    	team_id: "[YOUR TEAM ID]"
    	bundle_id: "[YOUR APP BUNDLE ID]"
    )
  end

  lane :release do
  	# This will run the retrofitted UI Tests for you and create snapshots... :-)
  	snapshot(
      output_simulator_logs: true,
      reinstall_app: false,
      erase_simulator: true,
      scheme: "ionic-screen-shots" # The name of a scheme to use, one that you generated with ionic_ios_config_snapshot
    )
  end
end

You can now use this to fully automate the build process between ionic and fastlane, including snapshots.

There is also no limit to the number of different schemes you can create and use, so you could have one scheme for one lane and a whole different scheme for another lane.

Run tests for this plugin

To run both the tests, and code style validation, run

rake

To automatically fix many of the styling issues, use

rubocop -a

Issues and Feedback

For any other issues and feedback about this plugin, please submit it to this repository.

Troubleshooting

If you have trouble using plugins, check out the Plugins Troubleshooting guide.

Using fastlane Plugins

For more information about how the fastlane plugin system works, check out the Plugins documentation.

About fastlane

fastlane is the easiest way to automate beta deployments and releases for your iOS and Android apps. To learn more, check out fastlane.tools.

fastlane-plugin-ionic_integration's People

Contributors

0verrfl0w avatar acelondon avatar janpio avatar knocknarea avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

fastlane-plugin-ionic_integration's Issues

Questions for understanding the code

Looking at the code right now, trying to understand some things. I know this is quite old now, but maybe you still remember:

  1. ionic_ios_config_snapshot_action copies the test files for one scheme name (ui-snapshots by default). But then ionic_ios_snapshot_action loops over all schemes it finds. Why is that?

  2. Why is this output when it opens the project?

    UI.message("Xcode Project is Version #{proj.root_object.compatibility_version} Compatible")

  3. Why is ionic_min_target_os a parameter? Where and why would one need this?

  4. Why the configurable scheme name? Is there any use to be able to give this a specific name that I don't see (yet)?

Getting error on install

Hello thanks for great work. I am getting following error when trying to install your plugin:

Make sure to commit your Gemfile, Gemfile.lock and Pluginfile to version control
Installing plugin dependencies...
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory:
~/.fastlane/bin/bundle/lib/ruby/gems/2.2.0/gems/json-2.1.0/ext/json/ext/generator
~/.fastlane/bin/bundle/bin/ruby -r ./siteconf20170706-9154-d5dv0d.rb extconf.rb
creating Makefile

current directory:
~/.fastlane/bin/bundle/lib/ruby/gems/2.2.0/gems/json-2.1.0/ext/json/ext/generator
make "DESTDIR=" clean

current directory:
~/.fastlane/bin/bundle/lib/ruby/gems/2.2.0/gems/json-2.1.0/ext/json/ext/generator
make "DESTDIR="
compiling generator.c
clang: warning: no such sysroot directory:
'/Applications/Xcode-7.3.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.1
1.sdk'
[-Wmissing-sysroot]
In file included from generator.c:1:
In file included from ./../fbuffer/fbuffer.h:5:
In file included from ~/.fastlane/bin/bundle/include/ruby-2.2.0/ruby.h:33:
In file included from ~/.fastlane/bin/bundle/include/ruby-2.2.0/ruby/ruby.h:29:
~/.fastlane/bin/bundle/include/ruby-2.2.0/ruby/defines.h:26:10: fatal error:
'stdio.h' file not found
#include <stdio.h>
         ^
1 error generated.
make: *** [generator.o] Error 1

make failed, exit code 2

Gem files will remain installed in
~/.fastlane/bin/bundle/lib/ruby/gems/2.2.0/gems/json-2.1.0 for inspection.
Results logged to
~/.fastlane/bin/bundle/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-15/2.2.0-static
/json-2.1.0/gem_make.out

An error occurred while installing json (2.1.0), and Bundler cannot continue.
Make sure that `gem install json -v '2.1.0'` succeeds before bundling.


Got it working, but where is the record button?

Hello and thank you for providing this plugin - I managed to set it up in our environment (it took some time as I had an issue with using fastlane plugins at all) and followed your detailed instructions, but I can't see the red record button as shown in your screenshot. Perhaps I have to change some view settings to let it appear...
I am totally new to XCode, sorry.

Is there a keyboard shortcut to use instead of the button? Any idea?
Thank you for helping me out,
Anne

Your './fastlane/ionic/config/ios/ui-tests/ionic-screen-shots/SnapshotHelper.swift' is outdated, please run `fastlane snapshot update`

While running the lane from the README for the first time I get this:

[04:28:30]: Your './fastlane/ionic/config/ios/ui-tests/ionic-screen-shots/SnapshotHelper.swift' is outdated, please run `fastlane snapshot update`
[04:28:30]: to update your Helper file
+---------------+--------------+
|         Lane Context         |
+---------------+--------------+
| PLATFORM_NAME | ios          |
| LANE_NAME     | ios snapshot |
+---------------+--------------+
[04:28:32]: Please update your Snapshot Helper file

+------+---------------------+-------------+
|             fastlane summary             |
+------+---------------------+-------------+
| Step | Action              | Time (in s) |
+------+---------------------+-------------+
| 1    | Verifying required  | 0           |
|      | fastlane version    |             |
| ๐Ÿ’ฅ   | snapshot            | 72          |
+------+---------------------+-------------+

[04:28:32]: fastlane finished with errors

[!] Please update your Snapshot Helper file

The version in /fastlane indeed seems to be version 1.4 while the generated one is version 1.3, the difference is one line almost at the end.

Copying the changes over manually fixed this error for now.

Error in the version of screengrab

Hi, Could be good to update the Screengrab version that is added in the build-extra.gradle, from androidTestCompile 'tools.fastlane:screengrab:1.0.0' to androidTestCompile('tools.fastlane:screengrab:1.2.0') because i had some issues trying to take the screenshots on android.

[!] Unable to locate Main Target for Ionic App in MyApp

When I run bundle exec fastlane run ionic_ios_config_snapshot ionic_scheme_name:ionic-screen-shots I get this output:

Jans-MBP:stromzaehler sujan$ bundle exec fastlane run ionic_ios_config_snapshot ionic_scheme_name:ionic-screen-shots
+------------------------+---------+------------------------+
|                       Used plugins                        |
+------------------------+---------+------------------------+
| Plugin                 | Version | Action                 |
+------------------------+---------+------------------------+
| fastlane-plugin-updat  | 1.0.1   | update_xcodeproj       |
| e_xcodeproj            |         |                        |
| fastlane-plugin-ionic  | 0.1.3   | ionic_ios_config_snap  |
| _integration           |         | shot                   |
|                        |         | ionic_ios_snapshot     |
+------------------------+---------+------------------------+

[03:56:16]: ---------------------------------------
[03:56:16]: --- Step: ionic_ios_config_snapshot ---
[03:56:16]: ---------------------------------------
[03:56:16]: Creating New UI Unit Tests for Snapshots, with Scheme ionic-screen-shots in fastlane/ionic/config/ios/ui-tests
[03:56:16]: Copying iOS UI Tests from /Users/sujan/.fastlane/bin/bundle/lib/ruby/gems/2.2.0/gems/fastlane-plugin-ionic_integration-0.1.3/lib/fastlane/plugin/ionic_integration/resources/ios/ui-snapshots to fastlane/ionic/config/ios/ui-tests/ionic-screen-shots
[03:56:16]: Configuring Xcode with UI Tests Located in fastlane/ionic/config/ios/ui-tests/**
[03:56:16]: Found ["fastlane/ionic/config/ios/ui-tests/ionic-screen-shots/"]...
[03:56:16]: Setting up ionic-screen-shots as UI Unit Test folder and Scheme in platforms/ios for Xcode Project MyApp
[03:56:16]: Xcode Project is Version Xcode 3.2 Compatible
[03:56:16]: Creating UI Test Group ionic-screen-shots for snapshots testing
[03:56:16]: Finding Main Target (of the Project)...

[!] Unable to locate Main Target for Ionic App in MyApp

Any idea what could cause this?

Future development?

Are you planning on any future development of this plugin?
Adding screengrab for Android?
Other Ionic/Cordova specific behaviour?

README Images

Just a place to hold images in the README.md file.

screen shot 2017-04-25 at 10 02 13

screen shot 2017-04-25 at 10 05 58

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.