TGW គឺ ជា ការ រចនា និង ដំណោះស្រាយ សម្រាប់ ប្រព័ន្ធ ការ គ្រប់គ្រង សារ
When you have screens within your Android app that have camera and/or gallery features with some screen changes (views, labels or buttons that appear/disappear, etc) and you need to write some Espresso tests for those features/screens there are a couple of helpers that Ive been using and I want to share with you all.Granting PermissionsWhen you are using the Camera within your app, you need to grant some permissions in the device in order to read/store a photo. These permissions are asked in runtime an usually are related to READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE.
Thus, the GrantPermissionRule allows granting of runtime permissions on Android M (API 23) and above and when applied to a test class this Rule attempts to grant all requested runtime permissions.@get:Rulevar mRuntimePermissionRule = GrantPermissionRule.grant(android.
Manifest.permission.WRITE_EXTERNAL_STORAGE)This Rule is usually used to grant runtime permissions to avoid the permission dialog from showing up and blocking the Apps Ui, and according to official documentation:As per this rule will automatically grant READ_EXTERNAL_STORAGE when WRITE_EXTERNAL_STORAGE is requestedGallery TestThe code to test when a gallery icon is clicked in the app, then an image is picked and shown in the screen:The first thing here is that I have a helper method (CameraAndGallery.
savePickedImage) that first saves an image (for brevity the ic_launcher icon) that is going to be used in the test as a local file visible for the test:The activity parameter comes from the ActivityTestRule:@get:Rulevar mActivityTestRule = IntentsTestRule(MyActivity::class.java)Then I create an ActivityResult object (like a mock but for Android Intent) that is going to be used by the Espresso Intents matcher (to match and validate the outgoing intents):val imgGalleryResult = CameraAndGallery.createImageGallerySetResultStub(mActivityTestRule.
activity) intending(hasAction(Intent.ACTION_CHOOSER)).respondWith(imgGalleryResult)The secret here is to ask for the file previously saved and finally used as the result.
Note: To work with espresso intents, we must to add this dependency to apps build. gradle file:androidTestImplementation androidx.test.
espresso:espresso-intents:$espressoVersionFor the test we are writing, lets asume that the image picked from the Gallery, we are setting it in an ImageView that is visible for the user, then the final part of the test is to check that the image is displayed (method hasImageSet()):onView(withId(R.id.auctionphotos_bigimage_viewer)).
check(matches(hasImageSet()))Camera TestSimilar to Gallery Test, the test to get an image from the device Camera follows the almost the same steps, but in this case an image doesnt need to be saved before, only mock the result of the camera:The mocked capture result as follows:The resulting image is going to be taken by the intent:intending(hasAction(MediaStore. ACTION_IMAGE_CAPTURE)). respondWith(imgCaptureResult)And with that we can check if the image was taken and displayed:onView(withId(R.
id.auctionphotos_bigimage_viewer)).check(matches(hasImageSet()))Finally, if you want to explore a little bit more content regarding Espresso tests and Intents, you may want to take a look of this repo from official Android team
Shenzhen TigerWong Technology Co., Ltd
ទូរស័ព្ទ ៖86 13717037584
អ៊ីមែល៖
Info@sztigerwong.comGenericName
បន្ថែម ៖ ជុំ 601-6000 ឡុងទហា កណ្ដាល ឡុង ហ៊ូ វ៉ាន
{"site":{"site_id":2877,"site_type":1,"site_domain":"sztigerwong.com","domain_mode":2,"original_domain":"sztigerwong.com","language_code":"km","is_init_domain":0,"is_shop":false,"is_ssl":0,"lang_prefix":"/km","animate_name":"none","compress__ratio":"70,60,60","img__dpi":"true"},"page":{"page_id":733,"page_type":"ai_article_detail","page_code":423,"page_url":"/ai-article/testing-camera-and-gallery-intents-with-espresso.html","page_source":"","allowAnimat":0,"content_id":170,"content_type":5,"detail_thumb":"https://img.yfisher.com/1612248458188.jpg","detail_title":"Testing Camera and Gallery Intents with Espresso","moq":1},"translateList":{"A new item has been added to your Shopping Cart":"ធាតុថ្មីត្រូវបានបន្ថែមទៅក្នុងរទេះដើរទិញឥវ៉ាន់របស់អ្នក","account":"កននេយ្យ","Account Name":"ឈ្មោះគណនី","Account Number":"លេខគណនី","Account is not exists":"គណនីមិនមានទេ","account security":"សុវត្ថិភាពគណនី","Active Commission":"គណៈកម្មការសកម្ម","Add a review on the product":"បន្ថែមការពិនិត្យឡើងវិញលើផលិតផល","Add to":"បន្ថែមលើ","Add to Cart":"បន្ថែមទៅរទេះ","address book":"សៀវភៅអាស័យដ្ឋាន","affiliate links":"តំណភ្ជាប់ពាក់ព័ន្ធ","all":"តាមងអស់","All Orders":"ការបញ្ជាទិញទាំងអស់","Already commented":"បានផ្តល់យោបល់រួចហើយ","Are you sure to cancel this withdrawal?":"តើអ្នកប្រាកដជាបោះបង់ការដកប្រាក់នេះមែនទេ?","Are you sure to delete the selected items?":"តើអ្នកប្រាកដជាលុបធាតុដែលបានជ្រើសរើសមែនទេ?","Are you sure you want to delete it?":"តើអ្នកពិតជាចង់លុបវាចោលឬ?","Awaiting Payment":"រង់ចាំការទូទាត់","Awaiting Shipment":"កំពុងរង់ចាំការដឹកជញ្ជូន","Back":"រតលប់","Bank Transfer":"ការផ្ទេរប្រាក់តាមធនាគារ","bank address":"អាស័យដ្ឋានធនាគារ","basic information":"ព័ត៌មានមូលដ្ឋាន","Buy":"តិញ","Buy Now":"ទិញឥឡូវនេះ","bank name":"ឈ្មោះរបស់ធនាគារ","city":"តីរកុង","Copy successful":"ចម្លងដោយជោគជ័យ","Copy failed":"ចម្លងបានបរាជ័យ","Can Extract":"អាចទាញយកបាន","Currency Type":"ប្រភេទរូបិយប័ណ្ណ","Cancel":"លប់ចោល","Cancel the success":"បោះបង់ភាពជោគជ័យ","Cancelled":"លប់លានផាក","Choose a country":"ជ្រើសរើសប្រទេសមួយ","Choose Coupon":"ជ្រើសរើសគូប៉ុង","Choose items":"ជ្រើសរើសធាតុ","Clear":"ផ្លឺ","Clear Search":"ស្វែងរកយ៉ាងច្បាស់","Comment Successful!":"មតិយោបល់ទទួលបានជោគជ័យ!","Comment Failed!":"មតិយោបល់បានបរាជ័យ!","Commission Details":"ព័ត៌មានលំអិតរបស់គណៈកម្មការ","Commission":"ផារៈ","Commission Status":"ស្ថានភាពគណៈកម្មការ","commodity payment":"ការទូទាត់ទំនិញ","completed":"completed","Completed":"បានបញ្ចប់","Condition not met":"លក្ខខណ្ឌមិនត្រូវបានបំពេញ","Confirm":"បហ្ជាក់","Confirm password is inconsistent with new password":"បញ្ជាក់ពាក្យសម្ងាត់មិនគួរឱ្យមិនស្ថិតស្ថេរជាមួយនឹងពាក្យសម្ងាត់ថ្មី","Congratulations":"សេចក្ដីសរសើររឺអបអរ","Congratulations! You are got a coupon.":"អបអរសាទរ! អ្នកមានគូប៉ុង។","Congratulations! You are got all coupons.":"អបអរសាទរ! អ្នកទទួលបានប័ណ្ណទាំងអស់។","Continue":"បន្ដ","Continue Shopping":"បន្តទិញទំនិញ","Copy the code and use it directly in the shopping cart.":"ចម្លងកូដហើយប្រើវាដោយផ្ទាល់នៅក្នុងរទេះដើរទិញឥវ៉ាន់។","Country":"រសុករេស","Coupon code":"លេខកូដប័ណ្ណ","Coupon List":"បញ្ជីគូប៉ុង","Date":"កាលកមនត់","days after receiving":"ថ្ងៃបន្ទាប់ពីទទួលបាន","Design customization":"ការប្តូរតាមបំណងរចនា","Do not use any discount":"កុំប្រើការបញ្ចុះតម្លៃណាមួយ","Earliest":"ឆាប់បំផុត","Export successful":"នាំចេញបានជោគជ័យ","Export failed":"ការនាំចេញបានបរាជ័យ","email":"អ៊ីមែល","email format does not match":"ទ្រង់ទ្រាយអ៊ីមែលមិនត្រូវគ្នាទេ","Estimated Delivery Time":"ពេលវេលាដឹកជញ្ជូនប៉ាន់ស្មាន","Effective Order Count":"ការរាប់តាមការបញ្ជាទិញប្រកបដោយប្រសិទ្ធភាព","Effective Sale Amount":"ចំនួនលក់មានប្រសិទ្ធិភាព","Expense":"ការចមនាយ","expired":"ផុតសុក","export a report?":"នាំចេញរបាយការណ៍?","Failed to upload files.":"Failed to upload files.","FAQ":"FAQ","Find Parts":"ស្វែងរកផ្នែក","for order over":"សម្រាប់ការបញ្ជាទិញ","Free":"ដេលមានសេរីផាប","Free Quote & Information Request":"ការដកស្រង់និងការស្នើសុំព័ត៌មានឥតគិតថ្លៃ","Free Shipping":"ការដឹកជញ្ជូនដោយឥតគិតថ្លៃ","Get":"តតយល / បាន","Get coupons":"ទទួលបានប័ណ្ណ","Get discount":"ទទួលបានការបញ្ចុះតំលៃ","Get it":"ទទួលបាន","Get it after logging in and use it in the shopping cart.":"ទទួលបានវាបន្ទាប់ពីចូលហើយប្រើវានៅក្នុងរទេះដើរទិញឥវ៉ាន់។","Go to Page":"ទៅកាន់ទំព័រ","Highest Price":"តម្លៃខ្ពស់បំផុត","home":"ផ្ទហ","Hot Sale":"លក់ក្តៅ","Income":"របាក់ចមនុល","Incorrect form format":"ទ្រង់ទ្រាយទម្រង់មិនត្រឹមត្រូវ","Inquiry":"ការសើបអង្កេត","join guide":"ចូលរួមមគ្គុទេសក៍","Last 30 days":"30 ថ្ងៃចុងក្រោយ","Last 7 days":"7 ថ្ងៃចុងក្រោយ","Links report":"របាយការណ៍តំណភ្ជាប់","Loading":"កំពុងផ្ទុក","Lowest Price":"តម្លៃទាបបំផុត","Match Product":"ផលិតផលប្រកួត","Merchant Free Shipping":"ការដឹកជញ្ជូនទំនិញឥតគិតថ្លៃ","message":"ប៍តមាន","Most Popular":"ពេញនិយមបំផុត","my account":"គណនីរបស់ខ្ញុំ","my coupons":"ប័ណ្ណរបស់ខ្ញុំ","my inquiry":"ការសាកសួររបស់ខ្ញុំ","my orders":"ការបញ្ជាទិញរបស់ខ្ញុំ","my reviews":"ការពិនិត្យឡើងវិញរបស់ខ្ញុំ","my wishlist":"បញ្ជីប្រាថ្នារបស់ខ្ញុំ","name":"ឈ្ផោហ","New Arrival":"មកដល់ថ្មី","Newest":"ថ្មីបំផុត","No Quotation":"គ្មានការដកស្រង់","No time limit":"គ្មានដែនកំណត់ពេលវេលា","Not deleted":"មិនបានលុប","not valid yet":"មិនមានសុពលភាពនៅឡើយទេ","Off":"រលត់","Offers and Discounts":"ការផ្តល់ជូននិងការបញ្ចុះតម្លៃ","ok":"យល់ព្រម","Only DOC,DOCX,PDF,PNG,JPEG and JPG files can be uploaded":"មានតែ DOC, Docx, PDF, PDF, JPEG និង JPG ប៉ុណ្ណោះដែលអាចផ្ទុកឡើងបាន","optional":"តាមចមរើស","order notes":"កំណត់ត្រាបញ្ជាទិញ","Order over":"បញ្ជាទិញលើ","order id":"លេខសម្គាល់លំដាប់","order status":"ស្ថានភាពបញ្ជាទិញ","order amount":"ចំនួនទឹកប្រាក់បញ្ជាទិញ","Orders Report":"របាយការណ៍បញ្ជាទិញ","Other":"ផ្សេងទៀត","Password contains at least numbers and letters length should be 6-20":"លេខសម្ងាត់មានយ៉ាងហោចណាស់ចំនួនលេខនិងប្រវែងអក្សរគួរតែ 6-20","Password is invalid":"ពាក្យសម្ងាត់មិនត្រឹមត្រូវ","Password length should be 6-20":"ប្រវែងលេខសម្ងាត់គួរតែមាន 6-20","Paypal":"ស្យេវកាស","paypal payment":"ការទូទាត់ PayPal","Pending":"ដេលមិនតាន់សរមច","Pending Commission":"គណៈកម្មការដែលមិនទាន់សម្រេច","personal info":"ព័ត៌មានផ្ទាល់ខ្លួន","Please click ’click to continue’ to retry.":"សូមចុច \"ចុចដើម្បីបន្ត\" ដើម្បីព្យាយាមម្តងទៀត។","Please contact customer service for cash withdrawal":"សូមទាក់ទងសេវាកម្មអតិថិជនសម្រាប់ការដកសាច់ប្រាក់","Please enter a valid email address":"សូមបញ្ចូលអាសយដ្ឋានអ៊ីមែលត្រឹមត្រូវ","Please enter the verification code":"សូមបញ្ចូលលេខកូដផ្ទៀងផ្ទាត់","Please login in first":"សូមចូលដំបូង","Please select attribute":"សូមជ្រើសរើសគុណលក្ខណៈ","Please select country/region":"សូមជ្រើសរើសប្រទេស / តំបន់","Please select superior":"សូមជ្រើសរើសសភាពខ្ពស់","Please select the number of ratings.":"សូមជ្រើសរើសចំនួននៃការផ្តល់ចំណាត់ថ្នាក់។","Please select your country":"សូមជ្រើសរើសប្រទេសរបស់អ្នក","Please upload the invoice file":"សូមផ្ទុកឯកសារវិក័យប័ត្រ","Processing":"ការអនុលោម","Product Name":"ឈ្មោះផលិតផល","Please fill in the delivery address before selecting the payment method":"សូមបំពេញអាសយដ្ឋានដឹកជញ្ជូនមុនពេលជ្រើសរើសវិធីបង់ប្រាក់","promotion center":"មជ្ឈមណ្ឌលផ្សព្វផ្សាយ","Promotion Link Click Amount":"តំណទាញយកការផ្សព្វផ្សាយចុចចំនួនទឹកប្រាក់","Promoted link clicks":"ការចុចតំណភ្ជាប់ការចុច","Promotion Order Count":"ចំនួនទឹកប្រាក់បញ្ជាទិញការផ្សព្វផ្សាយ","Promotion Reports":"របាយការណ៍ផ្សព្វផ្សាយ","read more":"អានបន្ថែម","Received commission":"ទទួលបានកំរៃជើងសារ","Refund":"ការសងរបាក់វិញ","Refuse":"បដីសេធ","Region":"តមបន់","Register Success":"ចុះឈ្មោះជោគជ័យ","Remittance":"របាក់ផ្ញើរតោអាេយ","Reviews":"ការពិនិត្យឡើងវិញ","reports":"របាយការណ៍","Sale ends in":"លក់បញ្ចប់","Save in wishlist":"រក្សាទុកក្នុងបញ្ជីប្រាថ្នា","Search":"ការឆេកឆេ","swift code":"លេខកូដរហ័ស","Select how to share":"ជ្រើសរើសរបៀបចែករំលែក","Select premium items to increase your chances of making money":"ជ្រើសរើសរបស់របរពិសេសបំផុតដើម្បីបង្កើនឱកាសរកលុយរបស់អ្នក","Share items to your channels.when other purchase a from your link, you can get commission.":"Share items to your channels.when other purchase a from your link, you can get commission.","Share Product":"ចែករំលែកផលិតផល","shipment successful":"ការដឹកជញ្ជូនទទួលបានជោគជ័យ","Shipping":"ការដឹកជបះ","Shipping Address":"អាសយដ្ឋានដឹកជញ្ជូន","Size guide":"មគ្គុទេសក៍ទំហំ","Small Text":"អត្ថបទតូច","Small Title":"ចំណងជើងតូច","Sort By":"តម្រៀបតាម","Sales Amount":"ចំនួនទឹកប្រាក់នៃការលក់","State/Province/Territory":"រដ្ឋ / ខេត្ត / ទឹកដី","Successfully delete":"លុបចោលដោយជោគជ័យ","Successfully save":"រក្សាទុកដោយជោគជ័យ","Thank you for trying":"សូមអរគុណចំពោះការព្យាយាម","The account has been deactivated, please contact customer service to activate":"គណនីត្រូវបានធ្វើឱ្យអសកម្មសូមទាក់ទងសេវាកម្មអតិថិជនដើម្បីធ្វើឱ្យសកម្ម","the content can not be blank":"ខ្លឹមសារមិនអាចទទេបានទេ","The coupon code has been copied and used in the shopping cart.":"លេខកូដប័ណ្ណត្រូវបានថតចម្លងនិងប្រើក្នុងរទេះដើរទិញឥវ៉ាន់។","The file name cannot exceed 100 characters":"ឈ្មោះឯកសារមិនអាចលើសពី 100 តួអក្សរទេ","The file size cannot exceed 2MB":"ទំហំឯកសារមិនអាចលើសពី 2 មេកាបៃបានទេ","The number of withdrawals on the day has been capped":"ចំនួននៃការដកប្រាក់នៅថ្ងៃត្រូវបានកំណត់","The subscription is successful, thank you for your participation":"ការជាវទទួលបានជោគជ័យសូមអរគុណចំពោះការចូលរួមរបស់អ្នក","The user center is out of service. Please contact customer service":"មជ្ឈមណ្ឌលអ្នកប្រើប្រាស់អស់សេវាកម្មហើយ។ សូមទាក់ទងសេវាកម្មអតិថិជន","There is no amount to withdraw":"មិនមានចំនួនទឹកប្រាក់ក្នុងការដកប្រាក់ទេ","There is no data to export":"មិនមានទិន្នន័យសម្រាប់នាំចេញទេ","This is Text":"នេះគឺជាអត្ថបទ","This is title":"នេះគឺជាចំណងជើង","This transaction has failed.":"ប្រតិបត្តិការនេះបានបរាជ័យ។","Time to shop":"ពេលវេលាដើម្បីទិញទំនិញ","Tips":"គាយរេសា","To be commented":"ត្រូវបានផ្តល់យោបល់","Total":"បុកសរុប","Tutorial":"ការណែនាំ","This Supplier/Shipping Company does not deliver to your selected Country/Region.":"ក្រុមហ៊ុនផ្គត់ផ្គង់ / ដឹកជញ្ជូននេះមិនផ្តល់ជូនប្រទេស / តំបន់ដែលអ្នកបានជ្រើសរើសទេ។","Update password success":"ធ្វើឱ្យទាន់សម័យពាក្យសម្ងាត់ជោគជ័យ","Upload Image":"ផ្ទុកឡើងរូបភាព","Upload up to 6 pictures":"ផ្ទុកឡើងរហូតដល់ 6 រូបភាព","uploading":"ផ្ទុកឡើង","used":"បានប្រើ","user center":"មជ្ឈមណ្ឌលអ្នកប្រើប្រាស់","Upload Invoice":"ផ្ទុកវិក័យប័ត្រ","valid now":"មានសុពលភាពឥឡូវនេះ","Validity period":"រយៈពេលសុពលភាព","View Cart & Checkout":"មើលរទេះ","views":"ទស្សនៈ","Valid for":"មានសុពលភាពសម្រាប់","Welcome to the website":"សូមស្វាគមន៍មកកាន់គេហទំព័រ","Western Union":"Western Union","When your buyers received and confirmed orders, you can get commission right now!":"នៅពេលដែលអ្នកទិញរបស់អ្នកបានទទួលនិងបញ្ជាក់ការបញ្ជាទិញអ្នកអាចទទួលបានកំរៃជើងសារឥឡូវនេះ!","Withdrawal":"ដករបមុល","Withdrawal success":"ការដកប្រាក់ទទួលបានជោគជ័យ","Withdrawal Method":"វិធីសាស្រ្តដកប្រាក់","Write a Review":"សរសេរសង្ខេបឡើងវិញ","Withdrawal Amount":"ចំនួនទឹកប្រាក់ដកប្រាក់","Yes":"បាត","Yesterday":"បីមសិលមិញ","You are clicking too fast":"អ្នកកំពុងចុចលឿនពេក","You are got a coupon.":"អ្នកមានគូប៉ុង។","You can select a maximum of 90 days":"អ្នកអាចជ្រើសរើសរយៈពេលអតិបរមា 90 ថ្ងៃ","You can withdraw the commission to your Paypal account.":"អ្នកអាចដកគណៈកម្មការទៅគណនី PayPal របស់អ្នក។","You haven’t chosen an address yet":"អ្នកមិនបានជ្រើសរើសអាសយដ្ឋាននៅឡើយទេ","You haven’t selected a product yet":"អ្នកមិនទាន់បានជ្រើសរើសផលិតផលនៅឡើយទេ","Your rating":"ការវាយតម្លៃរបស់អ្នក","Your review":"ការពិនិត្យឡើងវិញរបស់អ្នក","Your shipping address error":"កំហុសអាសយដ្ឋានដឹកជញ្ជូនរបស់អ្នក"}}