Skip to content

Commit

Permalink
Merge Android tutorials and update for Slate
Browse files Browse the repository at this point in the history
  • Loading branch information
bootstraponline committed May 18, 2014
1 parent c8ee6a8 commit f89934c
Show file tree
Hide file tree
Showing 59 changed files with 643 additions and 648 deletions.
17 changes: 13 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ RSpec::Core::RakeTask.new :spec
# When the 'rake' command is used without a task
task :default => :spec
tutorial_root = File.expand_path File.join(Dir.pwd, 'modules')
tutorial = Appium::Tutorial.new tutorial_root: tutorial_root
tutorial = Appium::Tutorial.new tutorial_root: tutorial_root

desc 'clean, generate markdown, then generate html'
task :html do
Expand Down Expand Up @@ -37,14 +37,23 @@ task :build do
tutorial.publish
end

desc 'Build then overwrite index.md in ../api_docs'
task :api => :build do
def api tutorial_name
folder = File.expand_path File.join(__dir__, '..', 'api_docs', 'source')
return unless File.exist? folder

src = File.expand_path File.join(__dir__, 'tutorials', 'en', '01_native_ios_automation.md')
src = File.expand_path File.join(__dir__, 'tutorials', 'en', tutorial_name)
dst = File.expand_path File.join(folder, 'index.md')
File.delete dst if File.exist? dst

FileUtils.copy_entry src, dst
end

desc 'Build then overwrite index.md in ../api_docs'
task :api => :build do
api '01_native_ios_automation.md'
end

desc 'Build 02 then overwrite index.md in ../api_docs'
task :api2 => :build do
api '02_native_android_automation.md'
end
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## Flaky Gem

<ruby>

[common flaky](/common/flaky_gem.md)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
## Module 2 - Ruby Appium Native Android Automation
# Native Android Automation

### Chapter 1 - Getting started with appium
This tutorial covers automating native Android apps in Ruby and Java. To select
the active language, click `Ruby` or `Java` on the left hand side. Code
samples and content will change based on the selected language.

# Getting started with appium

[introduction](/common/introduction.md)

In this chapter, we'll be preparing to automate a native Android app using appium
with Ruby.
In this chapter, we'll be preparing to automate a native Android app.
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
[install](/common/install.md)

[rubymine](/common/rubymine.md)
<ruby>

[rubymine](/common/rubymine.md)

</ruby>

<java>

[common Java IDE](/common/java_ide.md)

</java>
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#### Compiling the Android sample app
## Compiling the Android sample app

`cd` into the appium repository root. Running `./reset.sh --android --dev` will
build the sample AndroidApp app ApiDemos.

> * Configuring and cleaning/building Android test app: ApiDemos
`* Configuring and cleaning/building Android test app: ApiDemos`

After seeing `---- reset.sh completed successfully ----`,
you'll find appium's custom api demos at this location:

> /appium/sample-code/apps/ApiDemos/bin/ApiDemos-debug.apk
`/appium/sample-code/apps/ApiDemos/bin/ApiDemos-debug.apk`

Appium uses a modified ApiDemo app so make sure to use this version instead of
what's provided in the SDK. The Appium fork of API Demos is [on GitHub](https://github.com/appium/android-apidemos).

#### Origin of Api Demos
## Origin of Api Demos

The ApiDemos app is [provided by Google](http://developer.android.com/sdk/exploring.html)
in the Android SDK. Running the `$ android` command will allow you to download
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#### Prebuilt Android Sample App
## Prebuilt Android Sample App

I have a compiled version of the Api Demos apk on GitHub.

> https://github.com/appium/ruby_lib/raw/master/ruby_lib_android/api.apk
`https://github.com/appium/ruby_lib/raw/master/ruby_lib_android/api.apk`

Downloading from the above link will be faster than building from source.
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
#### Starting the console
## Starting the console

Appium Ruby Console needs a platform and app path to get started.

If you see the following warning, it's safe to ignore. `libdvm.so` is part of
the android platform and not something we control.

> WARNING: linker: libdvm.so has text relocations. This is wasting memory and
<code>
WARNING: linker: libdvm.so has text relocations. This is wasting memory and
is a security risk. Please fix.
</code>

We're developing locally, so create an appium.txt with the following:

```
<code>
$ nano appium.txt
[caps]
platformName = "android"
app = "./api.apk"
```
</code>

The appium.txt contains two important pieces of information.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#### Page Command
## Page Command

With the console started, the next step is to begin automation.
The `page` command prints a list of elements that are of interest.
Expand Down Expand Up @@ -90,86 +90,86 @@ ruby console.

The next set of information is the network traffic.

```
<code>
post /execute
{
:script => "mobile: getStrings"
}
get /source
```
</code>

In response to the page command, two network requests were sent. The
[selenium-webdriver gem](http://rubygems.org/gems/selenium-webdriver) is used
to generate these requests.

After that is the result of the page command.

```
<code>
TextView
class: android.widget.TextView
text: API Demos
resource_id: android:id/action_bar_title
id: activity_sample_code
```
</code>

`TextView` is the [android specific class name](http://developer.android.com/reference/android/widget/TextView.html)
for the element.

Under each element name is a list of properties.

```
<code>
TextView
class: android.widget.TextView
text: API Demos
resource_id: android:id/action_bar_title
id: activity_sample_code
```
</code>

In this case we see there's a class, text, resource_id,
and an id. To find by text we can use the text command.

```
<code>
> text('API Demos')
#<Selenium::WebDriver::Element:0x7f5348cbb3447ff2 id="1">
```
</code>
The text command will look for any text on screen.

To find by resource_id, we'd use:

```
<code>
> id('android:id/action_bar_title')
#<Selenium::WebDriver::Element:0x..fe9053092a74b142a id="2">
```
</code>
To find by strings.xml id, we'd use:

```
<code>
> id('activity_sample_code')
#<Selenium::WebDriver::Element:0x5c46252e10021cc id="4">
```
</code>
Once we've found the element, attributes such as text can be accessed.

```
<code>
> id('activity_sample_code').text
"API Demos"
```
</code>

These helper methods [are documented on GitHub](https://github.com/appium/ruby_lib/tree/master/docs).

To view all possible elements, there's a `source` command. The `page_class`
command will give you an overview of what classes exist on the current page.

```
<code>
> page_class
12x android.widget.TextView
4x android.widget.FrameLayout
2x android.widget.LinearLayout
2x android.view.View
1x android.widget.ListView
1x android.widget.ImageView
```
</code>

The page command excels at identifying the elements you're most likely
interested in automating. I encourage you to read through the existing docs
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#### uiautomatorviewer
## uiautomatorviewer

Google includes the uiautomatorviewer tool in the Android SDK.
uiautomator requires API 16 (Android 4.1, Jelly Bean) or above. Appium's
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#### Summary
## Summary

We compiled the open source API Demos app from source. Then the Appium
Ruby Console was used find elements with the page command. After ending the
Expand Down
Loading

0 comments on commit f89934c

Please sign in to comment.