تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
استيراد الوحدات المطلوبة
للبدء، استورِد الوحدات المطلوبة لمعالجة الأحداث Firebase Test Lab:
Node.js
// The Cloud Functions for Firebase SDK to set up triggers and logging.const{onTestMatrixCompleted}=require("firebase-functions/v2/testLab");const{logger}=require("firebase-functions");
# The Cloud Functions for Firebase SDK to set up triggers and logging.fromfirebase_functionsimporttest_lab_fn,params# The requests library to send web requests to Slack.importrequests
لتشغيل الدالة Firebase Test Lab، حدِّد معالجًا لحدث إكمال مصفوفة الاختبار. في هذا المثال، يتم تشغيل الدالة عند اكتمال الاختبار، ويتم استرداد بيانات مصفوفة الاختبار من عنصر CloudEvent، ويتم إرسال نتائج الاختبار المقابلة إلى قناة Slack:
Node.js
exports.posttestresultstoslack=onTestMatrixCompleted({secrets:["SLACK_WEBHOOK_URL"]},async(event)=>{// Obtain Test Matrix properties from the CloudEventconst{testMatrixId,state,outcomeSummary}=event.data;// Create the title of the messageconsttitle=`${getSlackmoji(state)}${getSlackmoji(outcomeSummary,)}${testMatrixId}`;// Create the details of the messageconstdetails=`Status: *${state}* ${getSlackmoji(state,)}\nOutcome: *${outcomeSummary}* ${getSlackmoji(outcomeSummary)} `;// Post the message to slackconstslackResponse=awaitpostToSlack(title,details);// Log the responselogger.log(slackResponse);});
@test_lab_fn.on_test_matrix_completed(secrets=["SLACK_WEBHOOK_URL"])defposttestresultstoslack(event:test_lab_fn.CloudEvent[test_lab_fn.TestMatrixCompletedData])-> None:"""Posts a test matrix result to Slack."""# Obtain Test Matrix properties from the CloudEventtest_matrix_id=event.data.test_matrix_idstate=event.data.stateoutcome_summary=event.data.outcome_summary# Create the title of the messagetitle=f"{slackmoji(state)}{slackmoji(outcome_summary)}{test_matrix_id}"# Create the details of the messagedetails=(f"Status: *{state}* {slackmoji(state)}\n"f"Outcome: *{outcome_summary}* {slackmoji(outcome_summary)}")# Post the message to Slackresponse=post_to_slack(title,details)# Log the responseprint(response.status_code,response.text)
يمكن إنشاء مصفوفات الاختبار من مصادر أو سير عمل مختلفة. لذلك، من المستحسن غالبًا إنشاء دوال تنفّذ إجراءات مختلفة استنادًا إلى المصدر أو السياق المهم الآخر للاختبار. للمساعدة في ذلك، يتيح لك
gcloud تمرير معلومات عشوائية عند بدء اختبار يمكن الوصول إليه لاحقًا في وظيفتك. على سبيل المثال:
gcloud beta firebase test android run \
--app=path/to/app.apk \
--client-details testType=pr,link=<path/to/pull-request>
تاريخ التعديل الأخير: 2025-09-06 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","easyToUnderstand","thumb-up"],["ساعَدني المحتوى في حلّ مشكلتي.","solvedMyProblem","thumb-up"],["غير ذلك","otherUp","thumb-up"]],[["لا يحتوي على المعلومات التي أحتاج إليها.","missingTheInformationINeed","thumb-down"],["الخطوات معقدة للغاية / كثيرة جدًا.","tooComplicatedTooManySteps","thumb-down"],["المحتوى قديم.","outOfDate","thumb-down"],["ثمة مشكلة في الترجمة.","translationIssue","thumb-down"],["مشكلة في العيّنات / التعليمات البرمجية","samplesCodeIssue","thumb-down"],["غير ذلك","otherDown","thumb-down"]],["تاريخ التعديل الأخير: 2025-09-06 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],null,["\u003cbr /\u003e\n\nImport the required modules\n\nTo get started, import the modules required for handling Firebase Test Lab\nevents: \n\nNode.js \n\n // The Cloud Functions for Firebase SDK to set up triggers and logging.\n const {onTestMatrixCompleted} = require(\"firebase-functions/v2/testLab\");\n const {logger} = require(\"firebase-functions\"); \n https://github.com/firebase/functions-samples/blob/c4fde45b65fab584715e786ce3264a6932d996ec/Node/quickstarts/testlab-matrix-completed/functions/index.js#L20-L22\n\nPython \n\n # The Cloud Functions for Firebase SDK to set up triggers and logging.\n from firebase_functions import test_lab_fn, params\n\n # The requests library to send web requests to Slack.\n import requests \n https://github.com/firebase/functions-samples/blob/c4fde45b65fab584715e786ce3264a6932d996ec/Python/testlab-to-slack/functions/main.py#L17-L21\n\nTrigger a function on TestMatrix completion\n\nTo trigger a Firebase Test Lab function, define a handler\nfor the test matrix completion event. In this example, the function\ntriggers on test completion, retrieves the test matrix data from\nthe CloudEvent object, and sends\nthe corresponding test results to a Slack channel: \n\nNode.js \n\n exports.posttestresultstoslack = onTestMatrixCompleted(\n {secrets: [\"SLACK_WEBHOOK_URL\"]},\n async (event) =\u003e {\n // Obtain Test Matrix properties from the CloudEvent\n const {testMatrixId, state, outcomeSummary} = event.data;\n\n // Create the title of the message\n const title = `${getSlackmoji(state)} ${getSlackmoji(\n outcomeSummary,\n )} ${testMatrixId}`;\n\n // Create the details of the message\n const details = `Status: *${state}* ${getSlackmoji(\n state,\n )}\\nOutcome: *${outcomeSummary}* ${getSlackmoji(outcomeSummary)}\n `;\n\n // Post the message to slack\n const slackResponse = await postToSlack(title, details);\n\n // Log the response\n logger.log(slackResponse);\n }); \n https://github.com/firebase/functions-samples/blob/c4fde45b65fab584715e786ce3264a6932d996ec/Node/testlab-to-slack/functions/index.js#L97-L119\n\nPython \n\n @test_lab_fn.on_test_matrix_completed(secrets=[\"SLACK_WEBHOOK_URL\"])\n def posttestresultstoslack(\n event: test_lab_fn.CloudEvent[test_lab_fn.TestMatrixCompletedData]) -\u003e None:\n \"\"\"Posts a test matrix result to Slack.\"\"\"\n\n # Obtain Test Matrix properties from the CloudEvent\n test_matrix_id = event.data.test_matrix_id\n state = event.data.state\n outcome_summary = event.data.outcome_summary\n\n # Create the title of the message\n title = f\"{slackmoji(state)} {slackmoji(outcome_summary)} {test_matrix_id}\"\n\n # Create the details of the message\n details = (f\"Status: *{state}* {slackmoji(state)}\\n\"\n f\"Outcome: *{outcome_summary}* {slackmoji(outcome_summary)}\")\n\n # Post the message to Slack\n response = post_to_slack(title, details)\n\n # Log the response\n print(response.status_code, response.text) \n https://github.com/firebase/functions-samples/blob/c4fde45b65fab584715e786ce3264a6932d996ec/Python/testlab-to-slack/functions/main.py#L70-L91\n\nAccess client details\n\nTest matrices may be created from different sources or workflows. It is\ntherefore often desirable to create functions that perform different actions\nbased on the source or other important context of the test. To help with this,\n`gcloud` allows you to pass arbitrary information when starting a test that can\nbe accessed later in your function. For example: \n\n gcloud beta firebase test android run \\\n --app=path/to/app.apk \\\n --client-details testType=pr,link=\u003cpath/to/pull-request\u003e\n\nAnd then to access the information in your function: \n\nNode.js \n\n const testType = event.data.clientInfo.details.testType;\n const link = event.data.clientInfo.details.link;\n\nPython \n\n test_type: str | None = event.data.client_info.details.get(\"testType\")\n link: str | None = event.data.client_info.details.get(\"link\")"]]