Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions android/examples/run-first-test/config.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"capabilities": {
"browserstack.user" : "YOUR_USERNAME",
"browserstack.key" : "YOUR_ACCESS_KEY",
"browserstack.user" : "automation55",
"browserstack.key" : "cQdZKWeLP3EbZEqbgLsc",
"project": "First Behave Android Project",
"build": "Behave Android",
"name": "first_test",
"browserstack.debug": true,
"app": "bs://<app-id>",
"app": "bs://7a1407039d81930909d5891ca1539471d782f526",
"device": "Google Pixel 3",
"os_version": "9.0"
}
Expand Down
11 changes: 5 additions & 6 deletions android/examples/run-first-test/features/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
if 'BROWSERSTACK_ACCESS_KEY' in os.environ: CONFIG['capabilities']['browserstack.key'] = os.environ['BROWSERSTACK_ACCESS_KEY']

def before_feature(context, feature):
desired_capabilities = CONFIG['capabilities']
context.browser = webdriver.Remote(
desired_capabilities=desired_capabilities,
command_executor="http://hub-cloud.browserstack.com/wd/hub"
)
desired_cap = CONFIG['capabilities']
context.driver = webdriver.Remote(
command_executor="http://hub-cloud.browserstack.com/wd/hub",
desired_capabilities=desired_cap)

def after_feature(context, feature):
# Invoke driver.quit() after the test is done to indicate to BrowserStack
# that the test is completed. Otherwise, test will appear as timed out on BrowserStack.
context.browser.quit()
context.driver.quit()
11 changes: 5 additions & 6 deletions android/examples/run-first-test/features/first_test.feature
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Test for BrowserStack sample Wikipedia Android app
# Note: If you have uploaded your app to BrowserStack update the test here
Feature: Wikipedia Search Functionality
Scenario: can find search results
Given I open the app and search for keyword "BrowserStack"
Then Search results should appear
Feature: POC for Appium-behave-BrowserStack
Scenario: Should increment click counter when button is clicked
Given I open the app
When I click the button "Click me"
Then I should see the text "You clicked 1 times"
30 changes: 14 additions & 16 deletions android/examples/run-first-test/features/steps/steps.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import time
from behave import *
from appium.webdriver.common.mobileby import MobileBy
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

@given(u'I open the app and search for keyword "{keyword}"')
def step_impl(context, keyword):
search_element = WebDriverWait(context.browser, 10).until(
EC.presence_of_element_located((MobileBy.ACCESSIBILITY_ID, "Search Wikipedia"))
)
search_element.click()

search_input = WebDriverWait(context.browser, 30).until(
EC.element_to_be_clickable((MobileBy.ID, "org.wikipedia.alpha:id/search_src_text"))
)
search_input.send_keys(keyword)
time.sleep(5)
@given(u'I open the app')
def step_impl(context):
pass

@when(u'I click the button "{buttonText}"')
def step_impl(context, buttonText):
button = WebDriverWait(context.driver, 30).until(
EC.element_to_be_clickable((MobileBy.XPATH, "//android.widget.TextView[@text='"+buttonText+"']")))
button.click()
time.sleep(2)

@then(u'Search results should appear')
def step_impl(context):
elems = context.browser.find_elements_by_class_name("android.widget.TextView")
assert len(elems) > 0, "results not populated"
@then(u'I should see the text "{textValue}"')
def step_impl(context, textValue):
textEl = context.driver.find_element_by_xpath("//*[starts-with(@text,'You clicked')]")
assert(textEl.text == textValue)
2 changes: 1 addition & 1 deletion android/examples/run-first-test/pavement.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
)

def run_behave_test():
sh('behave features/first_test.feature')
sh('behave features/first_test.feature --junit')

@task
@consume_nargs(1)
Expand Down
12 changes: 12 additions & 0 deletions android/examples/run-first-test/reports/TESTS-first_test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<testsuite name="first_test.POC for Appium-behave-BrowserStack" tests="1" errors="0" failures="0" skipped="0" time="4.625834" timestamp="2021-07-19T15:00:02.783526" hostname="BRCPQD0094"><testcase classname="first_test.POC for Appium-behave-BrowserStack" name="Should increment click counter when button is clicked" status="passed" time="4.625834"><system-out>
<![CDATA[
@scenario.begin
Scenario: Should increment click counter when button is clicked
Given I open the app ... passed in 0.000s
When I click the button "Click me" ... passed in 4.094s
Then I should see the text "You clicked 1 times" ... passed in 0.532s

@scenario.end
--------------------------------------------------------------------------------
]]>
</system-out></testcase></testsuite>