Skip to content

Upload UI tests #2626

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Mar 18, 2019
Merged

Upload UI tests #2626

merged 17 commits into from
Mar 18, 2019

Conversation

domdomegg
Copy link
Member

@domdomegg domdomegg commented Mar 17, 2019

Description

Fixes #705 (as I believe #2086 did unit tests, and this does UI tests so it should be all covered)

  • Increasing number of tests should decrease number of bugs
  • Key component of app is upload, this Espresso-based test validates it

Would hopefully catch issues like #2629

TODO

Having the test work automatically from a fresh install. Currently it requires running the app and logging in, and having a file called image.jpg in the base of the filesystem.

I'm not sure how to go about this, (hence the 'help needed'). I think this roughly breaks into two fairly separate parts:

  • Automatically logging in with credentials securely stored in Travis (not publicly on Github). Maybe this can be done in a similar way to how the APK signing keys work?
  • Updating the android image to have a sample image.jpg in /storage/emulated/0/ (symlink'ed from /mnt/sdcard and /sdcard/)

Also I'm worried that if the API is very slow, the delays I've put in the test at certain points to wait for responses won't be long enough - I'm not sure what we can do about this too.

These will need to be done to get this working on Travis, however as it's not actually running the Android tests at the moment we could merge anyways and fix this when we re-enable them.

Contributing

If you think you can help please do create a branch continuing mine and submit PRs back to domdomegg/test-upload :)

@codecov-io
Copy link

codecov-io commented Mar 17, 2019

Codecov Report

Merging #2626 into master will decrease coverage by 0.01%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #2626      +/-   ##
=========================================
- Coverage    2.77%   2.75%   -0.02%     
=========================================
  Files         259     260       +1     
  Lines       12365   12438      +73     
  Branches     1116    1125       +9     
=========================================
  Hits          343     343              
- Misses      11995   12068      +73     
  Partials       27      27
Impacted Files Coverage Δ
...r/free/nrw/commons/contributions/MainActivity.java 0% <0%> (ø) ⬆️
app/src/main/java/fr/free/nrw/commons/Media.java 1.53% <0%> (-0.04%) ⬇️
...n/java/fr/free/nrw/commons/MediaDataExtractor.java 0% <0%> (ø) ⬆️
...rw/commons/mwapi/ApacheHttpClientMediaWikiApi.java 0% <0%> (ø) ⬆️
...fr/free/nrw/commons/settings/SettingsFragment.java 0% <0%> (ø) ⬆️
...ommons/contributions/ContributionsSyncAdapter.java 0% <0%> (ø) ⬆️
...java/fr/free/nrw/commons/upload/UploadService.java 0% <0%> (ø) ⬆️
...fr/free/nrw/commons/media/MediaDetailFragment.java 0% <0%> (ø) ⬆️
...nrw/commons/achievements/AchievementsActivity.java 0% <0%> (ø) ⬆️
...in/java/fr/free/nrw/commons/mwapi/CustomMwApi.java 0% <0%> (ø) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d24bf20...fbceb9a. Read the comment docs.

@maskaravivek
Copy link
Member

Great initiative @domdomegg! I can try helping with some of the things that you have mentioned in the help section.

logging in

It should be quite simple. We can probably get a test user created as discussed in #2226.

and having a file called image.jpg

Yes, this should be possible via travis.

Can you resolve merge conflicts so that i can work on top of it?

@domdomegg
Copy link
Member Author

The idea in #2226 was to create a locked down user which we could share the password with so it could run instrumentation tests automatically on anyone's machine - for example tests on the contributions activity. I should have updated it before, but it doesn't seem possible as you can't block a user from changing their password. Also if a user is locked down it means we can't upload the test image.

Therefore I think we need a new test user which isn't locked down, but we just keep the login details secretly stored on Travis, and then expect people running tests requiring login on their own machines to login to their own test accounts.

@vanshikaarora
Copy link
Contributor

Hey @domdomegg , I want to contribute can you please tell about few test that you are not working upon so that I can write the unit tests :)

@domdomegg
Copy link
Member Author

Hey @domdomegg , I want to contribute can you please tell about few test that you are not working upon so that I can write the unit tests :)

I think this PR requires quite a few Travis config changes which only a few people have access to. I've just submitted #2636 which is a WIP on WelcomeActivityTest (the tutorial) with some TODO ideas there I'm not currently working on.

@domdomegg domdomegg changed the title [WIP] [Help needed] Upload UI tests [WIP] Upload UI tests Mar 17, 2019
@vanshikaarora
Copy link
Contributor

@domdomegg As far I have noticed the previous tests were written in Kotlin, so from now onwards are we writing the unit tests in java or in kotlin?

@domdomegg
Copy link
Member Author

@domdomegg As far I have noticed the previous tests were written in Kotlin, so from now onwards are we writing the unit tests in java or in kotlin?

Good point actually. All the unit tests are done in Kotlin, and the one instrumentation (android) test was done in Java so I continued in Java. Actually thinking about it properly I think we should use Kotlin for the instrumentation tests so all the tests are the same language.

@maskaravivek
Copy link
Member

Updating the android image to have a sample image.jpg in /storage/emulated/0/ (symlink'ed from /mnt/sdcard and /sdcard/)

@domdomegg I have raised a PR to fix this. Now in the setup phase, I generate an image programmatically and then use it for uploading.

https://github.com/domdomegg/apps-android-commons/pull/1

@maskaravivek
Copy link
Member

maskaravivek commented Mar 18, 2019

Another thing that we need to take care of is:

Runtime Permissions. As of now, I had to grant permission beforehand.

Edit: have added GrantPermissionRule to handle runtime permissions.

e.printStackTrace();
}

String fileUrl = "https://commons.wikimedia.beta.wmflabs.org/wiki/File:" +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we enhance this bit as well? We can probably call media wiki api to assert if the image was uploaded.

@maskaravivek
Copy link
Member

Apart from this, I am working on automating the login bit. Do we have other action items for making this master ready?

@domdomegg
Copy link
Member Author

Apart from this, I am working on automating the login bit. Do we have other action items for making this master ready?

I don't think so. There probably will be more annoying issues once we enable it in Travis though.

@maskaravivek
Copy link
Member

I don't think so. There probably will be more annoying issues once we enable it in Travis though.

Yes, the final goal should be to have everything work on a fresh install itself.

@misaochan
Copy link
Member

Wow, thanks @domdomegg ! :)

As the tests are run on Commons beta, I personally think it is OK to use a regular beta account. This:

Therefore I think we need a new test user which isn't locked down, but we just keep the login details secretly stored on Travis, and then expect people running tests requiring login on their own machines to login to their own test accounts.

Sounds like a good idea to me.

@maskaravivek
Copy link
Member

@domdomegg Have raised https://github.com/domdomegg/apps-android-commons/pull/2 to automate the login process.

@maskaravivek
Copy link
Member

@domdomegg Can we merge this PR now?

@domdomegg
Copy link
Member Author

@domdomegg Can we merge this PR now?

I think so

@domdomegg domdomegg changed the title [WIP] Upload UI tests Upload UI tests Mar 18, 2019
@maskaravivek maskaravivek merged commit db5290e into commons-app:master Mar 18, 2019
@domdomegg domdomegg deleted the test-upload branch March 18, 2019 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement upload tests
5 participants