EzDevInfo.com

espresso.js

Super minimal MVC library

What is the best way to use LESS with Espresso 2?

I recently started to use LESS for my CSS coding and also upgraded from CSSEdit to the recent Espresso 2 app. Is there a good LESS sugar out there for Espresso 2?

Im highly addicted to using the x-ray feature in Espresso and the inspector and I need my fix soon :)


Source: (StackOverflow)

Advertisements

Is there any Vim plug-in that can show the file hierarchy?

For folks who have used the Espresso editor, I'll love the right bar for showing the file hierarchy based on the tag nesting and open close. Is it possible in Vim?

I thought taglist was promising, but it's just too smart, it collects and categorize the class and method, but for me who want to know the file hierarchy to know the file structure need the basic feature like Espresso has.

Can taglist be used for this purpose?


Source: (StackOverflow)

How to get a list of elements in espresso?

I'm trying to automate an android native app using espresso framework and i can't find a way how to get list of elements. (for example i need to check all checkboxed on a page) in selenium I can do like this:

elements = self.driver.find_elements_by_xpath("//xpath")
for element in elements:
    //do stuff

Source: (StackOverflow)

Project update via TextMate (like Espresso)

I am thoroughly in love with TextMate. I program everything in it, including ASP.NET for my daily job. However, I have a license for Espresso, and I was looking at it recently and discovered that there is a "Publish" section that I knew about before, but I didn't know that it could compare my FTP directory with my local directory and publish only the changed files.

Over the past week I've been finding myself using Espresso just for that functionality. However, I was hoping there was a way to get this functionality inside TextMate. I know that you could use an AppleScript script with Cyberduck (my FTP client) to upload a file when it changes, but I have never got that working and it also doesn't include the ability to merge files like Espresso does.

Am I plumb out of luck? Am I stuck using two different programs for the forseeable future?


Source: (StackOverflow)

Android: Espresso click test fails in application using ListView

I am trying UI tests using Espresso. Tested application has ListView. When testing using perform(click()), the test fails. In this case, log is as follows.

I/TestRunner( 1147): android.support.test.espresso.PerformException: Error performing 'single click' on view '(with id: com.sarltokyo.addressbookormlite4.app:id/nameTv and is descendant of a:  displaying data matching: with name:  within adapter view matching: with id: android:id/list)'.

When I use longClick() instead of click(), the test does not fail. If the prodution code is implemented so that the long tapped row of list is deleted, the test certainly deletes the row by doing perform(longClick()).

I searched hints by searching in Google search and this stackoverflow and I found two hints.

  1. Using Espresso Idling Resource.
  2. Using a user-defined custom matcher.

I tried two ways to solve this problem, however all the trials failed.

The related production codes are as follows.

  1. Entity classes

1.1 Person

@DatabaseTable(tableName = "person")
public class Person {
    @DatabaseField(generatedId = true)
    private Integer id;
    @DatabaseField(unique = true)
    private String name;
    @DatabaseField(foreign = true, foreignAutoCreate = true, foreignAutoRefresh = true)
    private Address address;

    public Person() {
    }

    public Integer getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Address getAddress() {
        return address;
    }

    public void setAddress(Address address) {
        this.address = address;
   }
}

1.2 Address

@DatabaseTable(tableName = "address")
public class Address {

    @DatabaseField(generatedId = true)
    private Integer id;
    @DatabaseField
    private String zipcode;
    @DatabaseField
    private String prefecture;
    @DatabaseField
    private String city;
    @DatabaseField
    private String other;

    public Address() {
    }

    public Integer getId() {
        return id;
    }

    public String getZipcode() {
        return zipcode;
    }

    public void setZipcode(String zipcode) {
        this.zipcode = zipcode;
    }

    public String getPrefecture() {
        return prefecture;
    }

    public void setPrefecture(String prefecture) {
        this.prefecture = prefecture;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getOther() {
        return other;
    }

    public void setOther(String other) {
        this.other = other;
    }
}
  1. Adapter class

    public class AdapterEx extends ArrayAdapter<Person> {
    public AdapterEx(Context context, List<Person> persons) {
        super(context, R.layout.layout_main_item, persons);
    }
    
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Person person = getItem(position);
        if (convertView == null) {
            LayoutInflater inflater = LayoutInflater.from(getContext());
            convertView = inflater.inflate(R.layout.layout_main_item, null);
        }
        convertView.setTag(position);
        convertView.findViewById(R.id.nameTv).setTag(position);
        TextView nameTv = (TextView)convertView.findViewById(R.id.nameTv);
        nameTv.setText(person.getName());
        return convertView;
    }
    

    }

  2. a part of MainActivity

     @Override
     public void personLoaderCallbacks(List<Person> callback) {
    dismissProgress(); 
    
    if (callback != null) {
        mPersonsAdapter = new AdapterEx(this, callback);
        mListView = (ListView)findViewById(android.R.id.list);
        mListView.setAdapter(mPersonsAdapter);
    
        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                updateAddress(view);
            }
        });
    
        mListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
                return deletePerson(view);
            }
        });
    } else {
        // todo
    }
    
    // todo
    LoaderManager manager = getLoaderManager();
    if (manager.getLoader(1) != null) {
        manager.destroyLoader(1);
    }
    

    }

In this code, AsyncTaskLoader is used. When doing perform(click()) in the test,the updateAddress method is called.

  1. the layout of row

layout_main_item.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          style="@style/ListItem"
          android:orientation="horizontal"
          android:layout_width="match_parent"
          android:layout_height="wrap_content">
    <TextView
        android:id="@+id/nameTv"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

  1. test code

The test code is as follows.

    public class MainActivity3Test extends BaseTestCase<MainActivity> {
    private final static String TAG = MainActivity3Test.class.getSimpleName();
    private ProgressIdlingResource3 mProgressIdlingResource;
    public MainActivity3Test() {
        super(MainActivity.class);
    }


    public void registerPersonLoaderIdlingResource() {

        Context context = getInstrumentation().getTargetContext();
        mProgressIdlingResource = new ProgressIdlingResource3(context);

        Espresso.registerIdlingResources(mProgressIdlingResource);
        Log.d(TAG, "registerIdlingResources");
    }

    public void unRegisterPersonLoaderIdlingResource() {
        Log.d(TAG, "unRegisterPersonLoaderIdlingResource");
        Espresso.unregisterIdlingResources(mProgressIdlingResource);
    }


    public void testClick() throws Throwable {
        // Creating dummy data
        cleanData();
        createTestData(200);

       // trial #1
       // registerPersonLoaderIdlingResource();

        MainActivity activity = getActivity();

        assertFalse(activity.isFinishing());
        final ListView listView = (ListView)activity.findViewById(android.R.id.list);
        assertEquals(200, listView.getCount());

        onData(anything()).inAdapterView(withId(android.R.id.list)).atPosition(0)
            .check(ViewAssertions.matches(ViewMatchers.isDisplayed()));

        // trial #2
        // onData(allOf(instanceOf(Person.class), myCustomObjectShouldHaveString("Hoge0")))
        //                .perform(click());
        // trial #3
        //onData(hasName("Hoge0")).inAdapterView(withId(android.R.id.list)).onChildView(withId(R.id.nameTv))
        //                .perform(click());

        // trial1
        //        unRegisterPersonLoaderIdlingResource();
}

In this code, BaseTestCase is as follows.

public class BaseTestCase<T extends Activity> extends ActivityInstrumentationTestCase2<T> {
    protected ContextLogic mContextLogic;
    private final static String TAG = BaseTestCase.class.getSimpleName();

    public BaseTestCase(Class<T> tClass) {
        super(tClass);
    }

    protected void setUp() throws Exception {
        super.setUp();
        Context context = getInstrumentation().getTargetContext();
        mContextLogic = new TestContextLogic(context);
        {   // Replace ContextLogicFactory to use RenamingDelegatingContext.
            ContextLogicFactory.replaceInstance(new ContextLogicFactory() {
                @Override
                public ContextLogic newInstance(Context context) {
                    return mContextLogic;
                }
            });
        }
        {   // Unlock keyguard and screen on
            KeyguardManager km = (KeyguardManager) getInstrumentation()
                .getTargetContext().getSystemService(Context.KEYGUARD_SERVICE);
            PowerManager pm = (PowerManager) getInstrumentation()
                .getTargetContext().getSystemService(Context.POWER_SERVICE);
            if (km.inKeyguardRestrictedInputMode() || !pm.isScreenOn()) {
                Intent intent = new Intent(getInstrumentation().getContext(), UnlockKeyguardActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                 getInstrumentation().getTargetContext().startActivity(intent);
                while (km.inKeyguardRestrictedInputMode()) {
                    SystemClock.sleep(100);
                }
            }
        }
    }

    public void cleanData() {
        Log.d(TAG, "cleanData");
        OpenHelper openHelper = mContextLogic.createOpenHelper();
        List<Person> persons = null;
        try {
            persons = openHelper.findPerson();
        } catch (SQLException e) {
            Log.e(TAG, e.getMessage());
        }

        for (Person person : persons) {
            try {
                openHelper.deletePerson(person.getName());
            } catch (SQLException e) {
                Log.e(TAG, e.getMessage());
            }
        }
    }

    public List<Person> createTestData(int personsNum) {
        Log.d(TAG, "createTestData");
        List<Person> persons = new ArrayList<Person>();
        // Creating dummy data.
        OpenHelper openHelper = mContextLogic.createOpenHelper();
        for (int i = 0; i < personsNum; i++) {
            Person person = new Person();
            Address address = new Address();
            address.setZipcode("123-456" + i);
            address.setPrefecture("Tokyo");
            address.setCity("Shinjyuku-ku");
            address.setOther("Higash-shinjyuku 1-2-" + i);
            person.setName("Hoge" + i);
            person.setAddress(address);
            try {
                openHelper.registerPerson(person);
                persons.add(person);
            } catch (SQLException e) {
                Log.e(TAG, e.getMessage());
            }
        }
        return persons;
    }
}

I tried three ways to solve this problem.

Trials

trial #1

At first time, I thought that the problem may be a timing one and that when the test clicks the specified row, the list may be not appeared yet and the test may fail. The data is saved in SQLite3 database. I thought that loading data time may be long, so I thought that I have to use AsyncTaskLoader and Idling Resource. I made a Thread-safe Singleton pattern class as follows and used a variable mIsRunning to show the AsyncTaskLoader running state.

public class RunningStatusClass {

    private static RunningStatusClass instance;

    private boolean mIsRunning = false;

    public static synchronized RunningStatusClass getInstance() {
        if (instance == null) {
            instance = new RunningStatusClass();
        }
        return instance;
    }

    private RunningStatusClass() {
    }

    public synchronized boolean isRunning() {
        return mIsRunning;
    }

    public synchronized void setRunningStatus(boolean isRunning) {
        mIsRunning = isRunning;
    }
}

When AsyncTaskLoader starts, I set in appropiate places of production code.

RunningStatusClass.getIntance().setRunningStatus(true);

When when AsyncTaskLoader ends, I set in appropiate places of prodution code.

RunningStatusClass.getIntance().setRunningStatus(false);

And in the method isIdleNow of Idling Resource class, I wrote as follows.

@Override
public boolean isIdleNow() {
    boolean idle = !isLoaderRunning();
    if (idle && mResourceCallback != null) {
//            Log.d(TAG, "mResourceCallback.onTransitionToIdle");
        mResourceCallback.onTransitionToIdle();
    }
    return idle;
}
private boolean isLoaderRunning() {
    if (RunningStatusClass.getInstance().isRunning()) {
        return true;
    } else {
        return false;
    }
}

I used this trial, but click test failed too.

Trial #2.

Using custom matcher

I wrote a custom matcher as follows.

        public static Matcher<Object> myCustomObjectShouldHaveString( String expectedTest) {
            return myCustomObjectShouldHaveString( equalTo( expectedTest));
        }
        private static Matcher<Object> myCustomObjectShouldHaveString(final Matcher<String> expectedObject) {
            return new BoundedMatcher<Object, Person>( Person.class) {
                @Override
                public boolean matchesSafely(final Person actualObject) {
                    // next line is important ... requiring a String having an "equals" method
                    if( expectedObject.matches( actualObject.getName()) ) {
                        return true;
                    } else {
                        return false;
                    }
                }
                @Override
                public void describeTo(final Description description) {
                    // could be improved, of course
                    description.appendText("getnumber should return ");
                }
            };
        }

And I added the next line in the test code.

onData(allOf(instanceOf(Person.class), myCustomObjectShouldHaveString("Hoge0")))
                        .perform(click());

However, the click test failed too.

Trial #3

Using custom matcher

I wrote a custom matcher as follows.

public static Matcher<Object> hasName(final String personName){
    return new BoundedMatcher<Object, Person>(Person.class) {
        @Override
        public boolean matchesSafely(Person person) {
            return person.getName().matches(personName);
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("with name: ");
        }
    };
}

And I added the next line in the test code.

onData(hasName("Hoge0")).inAdapterView(withId(android.R.id.list)).onChildView(withId(R.id.nameTv))
                    .perform(click());

However, the click test failed too.

When doing the check of the specified row, it works well. So I think that the data certainly appears in the list. Why do the click tests fail?

Added comment.

The test

assertEquals(200, listView.getCount());

fails when using API Level 19 emulator.

junit.framework.AssertionFailedError: expected:<200> but was:<0>

When using API 21 Level emulator, the test is OK. I cannot understand the cause of this problem.


Source: (StackOverflow)

Clicking on UI, while the same ID is shared by other UI.Using espresso android

I am using ESPRESSO Android for Ui automation in android studio. I have problem in Clicking in the packet using one drawer.All packet have same id, the price (text) is subject to change depends on customer requirement. so cant use it as a unique Id. How to solve the dilemma to be able to click on any one packet?


Source: (StackOverflow)

Android - Use parse and ui test

I use parse for push notifications and I want to mock it responses for my tests with espresso :)

I don´t want to create variables based on buildTypes on anything like that, I´m searching a cleaner way or parse supports it?

How can I do it?


Source: (StackOverflow)

issue with importing android.support.test.*

I add this dependencies to gradle:

// Unit testing dependencies

testCompile 'junit:junit:4.12'

// Set this dependency if you want to use the Hamcrest matcher library

testCompile 'org.hamcrest:hamcrest-library:1.3'

// more stuff, e.g., Mockito

androidTestCompile 'org.mockito:mockito-core:1.+'
androidTestCompile "com.google.dexmaker:dexmaker:1.2"
androidTestCompile "com.google.dexmaker:dexmaker-mockito:1.2"

androidTestCompile 'com.android.support.test:runner:0.3'
androidTestCompile 'com.android.support.test:rules:0.3'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2'

// add this for intent mocking support

androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2'

// add this for webview testing support

 androidTestCompile 'com.android.support.test.espresso:espresso-web:2.2'

and sync build.gradle successfully but when i want to import this classes :

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;

the IDE (Android Studio 1.2) give me an error that Cannot resolve symbol test , I search too much and I didn't find any answer


Source: (StackOverflow)

Support for live preview of Haml in Coda or Espresso?

I just discovered the beautiful Haml and Sass, and want to develop in these languages but with live previews. Coda and Espresso both allow for beautiful live previews of HTML files, but previews of an Haml file simply show it as plain text.

While there exist sugars for Espresso that add syntax highlighting, which is nice, I would like something that automatically compiles Haml files to HTML, and then lets me preview that instead of Haml.

Does anything like this exist for either Coda, or Espresso, or for any other web development tool out there?

(If it makes a difference, I'm not developing for Ruby on Rails, I'm making a static website, so the Ruby on Rails plugin shouldn't help AFAIK. Software I tried out were StaticMatic and Middleman. StaticMatic's development seems discontinued, and for some reason MiddleMan refuses to work after creating my initial directory structure. Maybe I'm using it wrong.)


Source: (StackOverflow)

LESS 1.3.3, watch mode hogging a lot of CPU in espresso editor

I was using an older version of less (1.2.1) by accident and when I updated the .js to the most recent version (1.3.3) it seems that Espresso, my html/css editor, now takes 40% cpu and up to 90% when in development/watch mode. I've tried other versions and it seems like it happens with 1.3.1+. I've tried different variations of the watch mode and even disabling it completely and it's still using 40-50% cpu. I basically can't work with it now.

edit: It seems like it's mostly being caused by watch mode, which I highly depend on :(

This is what my site head looks like. Any suggestions would be appreciated as I do not understand js at all.

<!doctype html>
<html>

<head>

<meta charset="utf-8"/>

<title>Article Sample</title>

<meta name="viewport" content="width=device-width, initial-scale=1"/>
<!-- Adding "maximum-scale=1" fixes the Mobile Safari auto-zoom bug: http://filamentgroup.com/examples/iosScaleBug/ -->


<!-- Link directly to LESS stylesheet first -->
<link rel="stylesheet/less" rel='nofollow' href="style/default.less" type="text/css" media="screen" />
<link rel="stylesheet/less" rel='nofollow' href="style/tablet.less" type="text/css" media="screen" />
<link rel="stylesheet/less" rel='nofollow' href="style/mobile.less" type="text/css" media="screen" />
<link rel="stylesheet/less" rel='nofollow' href="style/wide-mobile.less" type="text/css" media="screen" />

<!-- Then link to LESS, and enable development watch mode -->
<script src="js/less-1.3.3.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8">
    less.env = "development";
    less.watch();
</script>
<!-- Voilà! Instant LESS previews in Espresso -->

<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->

</head> 

Source: (StackOverflow)

Publishing to Amazon S3 with Espresso

I've been looking around to get some clarity on this but it seems like I'm the only stupid one having a problem with it.

Case is, I can't connect to Amazon S3 with Espresso. Or I think the case is rather that I don't know how to. I mean, I have my username, access key and secret key. Espresso asks for the username and password. So which one is my password? What should I use as the "server"? The port? I just can't make it work.

Sorry for being stupid but please help me out here. I know there are many of yous who use both Espresso and Amazon S3.

Many thanks in advance.


Source: (StackOverflow)

Alternative of espresso for windows

Espresso has live preview feature which shows live changes of code as we write code.

I am searching for same feature in a tool for Windows ?

Dreamweaver has that one. but doesn't support JS. Is there any other web editor or IDE ?

Any help would be appreciated.


Source: (StackOverflow)

How to click on index on option menu using Espresso Android

I call on option menu through
openActionBarOverflowOrOptionsMenu(getInstrumentation().getTargetContext());

the menu appeared,I can click on the menu item through text, that is fine, but as the text is subject to change, let say to other language for different clients. So in the long run its not useful. For this reason I want Espresso to click on specific index for specific test case.

Now in the setting the Menu does not seems to have an ID. Now I want to click on specific index in the menu option let say index(4).


Source: (StackOverflow)

Find and Replace/Update links like Dreamweaver in other editors

I've been slowly weening myself off of Dreamweaver and using other editors like SublimeText and Espresso. But there are two features that are lacking in those editors that I still find the need to use Dreamweaver for:

1.) Find and Replace within entire current local site.

2.) Update links when a page is saved within another directory. For example, if you rename, or re-save a file that is open within another directory, Dreamweaver will ask you to update the links. This will then make sure that if the file is moved or saved to another directory it will update any links within the HTML for stylesheets, images, navigation, etc.

Does any know of any other apps or tools that might be able to accomplish those actions without having to crack open Dreamweaver?

Any input is greatly appreciated. Thanks!


Source: (StackOverflow)