2017-09-28 7 views
8

पर पर्यावरण चर को कैसे पास किया जाए, मैं एक पर्यावरण चर को flutter drive परीक्षण में पास करना चाहता हूं।एक फ्लटर ड्राइवर परीक्षण

लॉन्च किए गए एप्लिकेशन में मूल्य पढ़ने में सक्षम होने या परीक्षण कोड दोनों ठीक होंगे, क्योंकि मुझे एप्लिकेशन में इसकी आवश्यकता है और अगर मैं इसे केवल टेस्ट कोड में प्राप्त कर सकता हूं, तो मैं इसे एप्लिकेशन पर उपयोग कर सकता हूं driver.requestData()

उदाहरण के लिए ट्रैविस मुझे उन पर्यावरण चर निर्दिष्ट करने की अनुमति देता है जो किसी भी तरह से प्रकट नहीं होते हैं (जैसे स्क्रिप्ट सामग्री और लॉग आउटपुट)।

मैं एप्लिकेशन के अंदर उपयोग करने के लिए उपयोगकर्ता नाम और पासवर्ड निर्दिष्ट करना चाहता हूं।

Setting environment variables in Flutter एक समान प्रश्न है, लेकिन यह मेरे उपयोग के मामले के लिए अत्यधिक जटिल लगता है।

उत्तर

2

मैंने ड्राइवर परीक्षण चलाने से पहले एनवी चर में पढ़ने के लिए डार्ट के Platform.environment का उपयोग करने की कोशिश की और ऐसा लगता है कि यह ठीक काम करता है। नीचे एक साधारण उदाहरण है जो FLUTTER_DRIVER_RESULTS env चर का उपयोग कर परीक्षण सारांश के लिए आउटपुट निर्देशिका सेट करता है।

import 'dart:async'; 
import 'dart:io' show Platform; 

import 'package:flutter_driver/flutter_driver.dart'; 
import 'package:test/test.dart'; 

void main() { 
    // Load environmental variables 
    String resultsDirectory = 
    Platform.environment['FLUTTER_DRIVER_RESULTS'] ?? '/tmp'; 
    print('Results directory is $resultsDirectory'); 

    group('increment button test',() { 
    FlutterDriver driver; 

    setUpAll(() async { 
     // Connect to the app 
     driver = await FlutterDriver.connect(); 
    }); 

    tearDownAll(() async { 
     if (driver != null) { 
     // Disconnect from the app 
     driver.close(); 
     } 
    }); 

    test('measure',() async { 
     // Record the performance timeline of things that happen 
     Timeline timeline = await driver.traceAction(() async { 
     // Find the scrollable user list 
     SerializableFinder incrementButton = find.byValueKey(
      'increment_button'); 

     // Click the button 10 times 
     for (int i = 0; i < 10; i++) { 
      await driver.tap(incrementButton); 

      // Emulate time for a user's finger between taps 
      await new Future<Null>.delayed(new Duration(milliseconds: 250)); 
     } 

     }); 
     TimelineSummary summary = new TimelineSummary.summarize(timeline); 
     summary.writeSummaryToFile('increment_perf', 
      destinationDirectory: resultsDirectory, pretty: true); 
     summary.writeTimelineToFile('increment_perf', 
      destinationDirectory: resultsDirectory, pretty: true); 
    }); 
    }); 
} 
+0

मेरे पास परीक्षण फ़ाइल के बजाय "एप्लिकेशन कोड" में चल रहे परीक्षण हैं (इस प्रश्न को पोस्ट करने के बाद इस रणनीति में स्थानांतरित हो गए हैं)। मुझे लगता है कि यह एक पंजीकृत प्लगइन को gequest भेजकर डिवाइस/एमुलेटर पर चल रहे कोड को मानों को पारित करने के लिए काम कर सकता है। मैं फिर से चिल्लाऊंगा और आपको बता दूंगा। –

संबंधित मुद्दे