TGW เป็น professinal ในการออกแบบและการแก้ปัญหาสำหรับระบบการจัดการที่จอดรถ
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
เซินเจิ้น tigerwong เทคโนโลยีจำกัด
โทร:86 13717037584
E-mail:
Info@sztigerwong.com
เพิ่ม: ห้อง601-605, อาคาร6, 1980วิทยาศาสตร์และเทคโนโลยีสวนอุตสาหกรรม, Longhua Street, เขต Longhua, เซินเจิ้น
{"site":{"site_id":2877,"site_type":1,"site_domain":"sztigerwong.com","domain_mode":2,"original_domain":"sztigerwong.com","language_code":"th","is_init_domain":0,"is_shop":false,"is_ssl":0,"lang_prefix":"/th","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":"เท่านั้นที่สามารถอัปโหลดไฟล์ DOCX, PDF, PNG, 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","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":"โปรดเลือก 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":"รหัส Swift","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":"ขนาดไฟล์ต้องไม่เกิน 2MB","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":"สหภาพตะวันตก","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":"ข้อผิดพลาดในการจัดส่งของคุณข้อผิดพลาด"}}