Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Espresso Read String File Value

I want to keep a Sting and Raw file in my androidTest module and read it when needed in Espresso test.

I keep res folder under androidTest and able to sync and generate R file for the same. But when I tried to access string resource using

getTargetContext.getString(R.string.product_name) or using mAcitivityRule.getActivity.getString(R.string.product_name)I am getting some random value which is even not used anywhere in resource file.

String output: "res/drawable-v21/abc_action_bar_item_background_material.xml"

Is there any way I can keep and use String resource in my project test module and it will not add into my production build.

like image 223
Krishnakant Avatar asked Jul 25 '16 09:07

Krishnakant


People also ask

How do I get text from view in espresso?

The basic idea is to use a method with an internal ViewAction that retrieves the text in its perform method. Anonymous classes can only access final fields, so we cannot just let it set a local variable of getText() , but instead an array of String is used to get the string out of the ViewAction .

What is r string in android?

A string resource provides text strings for your application with optional text styling and formatting. There are three types of resources that can provide your application with strings: String. XML resource that provides a single string. String Array.

Where is the strings XML file located?

String. xml file present in the values folder which is sub folder of res folder in project structure.In Android Studio, we have many Views such as TextView,Button,EditText,CheckBox,RadioButton etc. These views have a common attribute named text.


1 Answers

In 2019 we should do (Kotlin).

val resources = ApplicationProvider.getApplicationContext<App>().resources

val description = resources.getString(DESCRIPTION)
like image 72
Andrii Kovalchuk Avatar answered Oct 17 '22 16:10

Andrii Kovalchuk