I'm hoping someone can help.
I am testing the Three App where correct behavior should be once the app launches, a splash screen is shown for a few seconds, then a login page is presented.
I'm trying to automate this using appium but once the automated test opens the splash screen, the test ends.
I am shown this error message:
NoSuchElementError: An element could not be located on the page using the given search parameters. at AndroidUiautomator2Driver.findElOrEls (C:\Users\zminhas\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-android-driver\lib\commands\find.js:75:11)
Here is my env.rb code:
require "appium_lib"
require "pry"
opts = {
caps: {
deviceName: :Anyname,
platformName: :Android,
app: 'C:\Users\zminhas\Desktop\three_app_automation\features\support\biometrics.apk',
appPackage: "com.hutchison3g.planet3",
appActivity: ".SplashScreenActivity",
noReset: true
},
appium_lib: {
#wait_timeout: 30
}
}
Appium::Driver.new(opts, true).start_driver
Appium.promote_appium_methods Object
And my hooks.rb code:
Before do
$driver.start_driver
end
After do
$driver.driver_quit
end
Here is the full results screen:
$ cucumber
*** WARNING: You must use ANSICON 1.31 or higher (https://github.com/adoxa/ansicon/) to get coloured output on Windows
Feature: All external URLs work as expected within the More Tab
2019-11-11 12:08:13 WARN Selenium [DEPRECATION] Selenium::WebDriver::Error::TimeOutError is deprecated. Use Selenium::WebDriver::Error::TimeoutError (ensure the driver supports W3C WebDriver specification) instead.
Scenario: test # features/more_tab.feature:3
Given I see the enter number screen # features/step_definitions/more_tab_steps.rb:1
An element could not be located on the page using the given search parameters. (Selenium::WebDriver::Error::NoSuchElementError)
NoSuchElementError: An element could not be located on the page using the given search parameters.
at AndroidUiautomator2Driver.findElOrEls (C:\Users\zminhas\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-android-driver\lib\commands\find.js:75:11)
./features/step_definitions/more_tab_steps.rb:2:in `"I see the enter number screen"'
features/more_tab.feature:4:in `Given I see the enter number screen'
Failing Scenarios:
cucumber features/more_tab.feature:3 # Scenario: test
1 scenario (1 failed)
1 step (1 failed)
0m14.888s
Thank you for your time
Try with following capabilities
deviceName: :Anyname,
platformName: :Android,
automation_name: :uiautomator2,
app: 'C:\Users\zminhas\Desktop\three_app_automation\features\support\biometrics.apk',
appPackage: "com.hutchison3g.planet3",
appActivity: ".SplashScreenActivity",
noReset: true
I was having the same issue when an app was given to me in an interview. but after 2 days I was able to find the solution to the issue related to Splash Screen being stuck and not going to the second screen using script/appium but manually it was working fine.
The issue is something related to INTENT Activity
Solution:
I added some extra line of code to script/capabilities to appium and it worked fine.
Try using these lines in capabilities for the apps that have splash screen issue.
capabilities.setCapability("androidCoverage","com.my.Pkg/com.my.Pkg.instrumentation.MyInstrumentation");
capabilities.setCapability("androidCoverageEndIntent","com.example.pkg.END_EMMA");
capabilities.setCapability("intentAction","android.intent.action.MAIN");
capabilities.setCapability("intentCategory","android.intent.category.LAUNCHER");
capabilities.setCapability("intentFlags","0x10200000");
Please Let me know if it worked for you also?
Related
In my test automation project, I am using ruby with capybara, cucumber and selenium.
(I already have devkit installed and chrome is starting normally)
When looking for an element in the site to select it, I am using the method driver.findElement (By.xpath (.... etc"), but when executing cucumber, it is indicating the following error:
I already removed and reinstalled the selenium-webdriver gem but it did not resolve.
Can someone help me in resolving why WebDriver does not seem to be valid in this context?
code example
(finding button logout using tag img, because the element don't have name or id)
After('#logout') do
element = driver.findElement(By.xpath("//img[#src='/Portal/img/user.png']"));
element.click
end
Result cucumber execution
Feature: Login
Description feature
DevTools listening on ws://127.0.0.1:60121/devtools/browser/c0bacc6e-697a-4614-b82c-eb324d587df5
#logout
Scenario: Login_OK # features/support/login.feature:14
Given that i access the main portal page HRP # features/step_definitions/login_steps.rb:1
When do login using "abc123" and "abc123password" # features/step_definitions/login_steps.rb:5
Then system do login # features/step_definitions/login_steps.rb:10
And show message "Welcome to Portal." # features/step_definitions/login_steps.rb:14
undefined local variable or method `driver' for # (NameError)
./features/support/hooks.rb:4:in `After'
Failing Scenarios:
cucumber features/support/login.feature:14 # Scenario: Login_OK
1 scenario (1 failed)
4 steps (4 passed)
0m5.457s
If you're using Capybara with Cucumber in a standard setup then you shouldn't be really ever be calling the selenium webdriver instance directly - driver (except for in some very rare circumstances). Instead you should be using the Capybara methods. What is available in your After hook depends on exactly how where you've includeed what but one of these will probably be avaialble
After('#logout') do
element = page.find(:xpath, ".//img[#src='/Portal/img/user.png']"));
element.click
end
or
After('#logout') do
element = Capybara.current_session.findElement(:xpath, ".//img[#src='/Portal/img/user.png']");
element.click
end
Note: there is probably a better way to locate the logout button than an XPath on the contained images source, but without seeing the HTML of the button it's impossible to say for sure (for instance, Capybaras button finder will match against the alt attribute of an img element nested inside a <button> element)
Newbie engineer question here, but I've searched and can't find a solution.
Environment: Mac OS, Chrome, Capybara with Selenium Chrome-driver, Ruby with Rspec running the test.
Situation:
Testing a React app where the user logs in using a username and password, followed by clicking on a sidebar nav link that loads up....followed by other actions. Capybara continues to fail to find the sidebar nav link to click on. I believe the sidebar nav is its own React component and loads asynchronously
App & Test Behavior:
Sometimes Capybara finds the link element, clicks the link and the test passes. Other times it completely fails to find the element and fails the test.
Solutions I've tried:
Upping the default time for finder methods to continue to search to 15+ seconds(I've never noticed the app take more than 5 seconds on anything)
I only have used finder methods that SHOULD be repeat-searching for the default time for the element to appear (page.find, page.has_css?, etc)before attempting the .click action. What I have found is that after the login happens, and while the nav is loading, the test just seems to fail with element not found. The page.find does NOT seem to continue to search for 15 seconds before failing - instead, the login happens, then a second later I get a fail with element not found.
I have tried passing a wait into the find (example: page.find(some element, wait:15).click . This runs into the same problem as above where it doesn't seem to continue searching for 15 seconds for the element to appear and then click it.
What does seem to work is adding in sleeps before searching for an element (example: login, sleep(5), page.find(something).click).
Unfortunately I'm having this same problem with other elements all over in the app - for example a div may have a bunch of cards in it. When a new card is added it takes 2-3 seconds to show up in the list (probably due to sending out the card info to the database, and refreshing the cards on the page). If I try and page.find immediately after adding a card, the test will almost immediately fail with an element not found message. If I add the card, sleep(3), THEN try page.find, it will find it.
I can't just add sleep all over the place in the app, because its huge and it would slow down the tests immensely. I think I've tried all the typically suggested fixes for asynchronous loading. Any idea what is going on here and what I can do to fix it
editing to add some requested code.
I'm using capybara 3.2.
We are using a bit of a page object style framework so I"ll try and post the actual test with its methods in bold and helper methods nested in it.
Its getting caught in the before action of this particular feature on the final method to click on the sidebar. I'm a little limited on what I can show, but I think this will make sense....
The actual before action:
before do
**app.launch_app(app.url)**
# this instantiates an instance of the framework and helper methods and # goes to the app url
**app.login.full_login(app.username('Some User'), app.password)**
# def full_login(user, pass)
# enter_email(user)
# def enter_email(user)
# return if already_logged_in?
# def already_logged_in?
# page.has_css?("a[href*='/me']", wait: false)
# end
# fill_field('email', user)
# def fill_field(field, text)
# sleep 0.1
# page.find("input[type=#{field}]").send_keys text
# end
# click_button 'Log In'
# def click_button(text)
# page.click_on text
# end
# end
# login_using_second_auth(user, pass)
# def login_using_second_auth(user, pass)
# page.fill_in 'username', with: user
# page.fill_in 'password', with: pass
# click_button 'Sign In'
# end
# end
app.nav.click_sidebar_link('Admin Account', 'Admin')
# def click_sidebar_link(link, section)
# sleep(2)
# page.find('div[class^=app__wrapper] > div > div > div', text:
# section)
# .find('span[class^=nav-item]', text: link).click
# end
end
Sorry that looks so messy, but I think you guys can make sense of it.
The test is flaky so after running it a few times I can't get the exact error, but its usually element not found on the span with the text Admin
I have to initiate a Appium webdriver using code below.
driver=Appium::Driver.new(desired_caps)
And it is working for starting an app and quits during execution.
Can any one please give examples on how to do the assert for element exists and specific value comparison?
You've created "driver", then next step is just
driver.start_driver
Then you can use all methods in appium ruby_lib, for example
driver.text('some text')
driver.button('button_name/id/text')
To check element exist:
exists { button('sign in') } ? puts('true') : puts('false')
You said it started then quit, it might be normal, it quits if test arrives the last step, except you add test steps or put some sleep time.
Highly recommend you to check the examples:
https://github.com/jlipps/appium-ruby-example
and also the ruby_lib doc:
https://github.com/appium/ruby_lib/tree/master/docs
Recently we upgraded our selenium web driver from 2.47.1 to 2.48.0.
With this upgrade I need to add sleep for a few seconds in rspec to pass. Spec was working properly without sleep with the older version.
sleep(inspection_time=5) // why do I need this?
my_form_page.save_button.click
// some assertion here
Edit
I tried using implicit wait instead of sleep.But it's not working. Is there any specific reason behind it?
Capybara.current_session.driver.browser.manage.timeouts.implicit_wait = 50
Generally speaking, rspec selenium tests are known to be "flakey". Sometimes rspec tries to search for an element before it appears on page due to many reasons (ie: element appears upon ajax response).
Here's a tip that may help you solve this, if you will wrap your capybara finders inside of a within block, your tests will wait until it finds that within selector FIRST before trying to run the code inside of it.
This more-often-than-not will help solve a test running too fast on a page that takes a while to load and your button or selector or whatever isn't actually on the page yet (which is why it fails).
So take a look at these 2 examples and try the within method...
# spec/features/home_page_spec.rb
require "spec_helper"
describe "the home page", type: :feature do
context "form" do
# THIS MIGHT FAIL!!!!
it "submits the form", js: true, driver: :selenium do
visit "/"
find("#submit_button").click
end
# THIS PROBABLY WILL PASS!!!
it "submits the form", js: true, driver: :selenium do
visit "/"
within "form" do
find("#submit_button").click
end
end
end
end
I'm using Capybara to fill in a form and download the results.
It's a bit slow when filling in the form, and I want to check if JavaScript is the culprit.
How do I turn off JavaScript?
The Ruby code was something similar to, but not the same as, the following (the following won't reproduce the error message, but it is somewhat slow).
require "capybara"
url = "http://www.hiv.lanl.gov/content/sequence/HIGHLIGHT/highlighter.html"
fasta_text = [">seq1", "gattaca" * 1000, ">seq2", "aattaca" * 1000].join("\n")
session = Capybara::Session.new(:selenium)
# Code similar to this was run several times
session.visit(url)
session.fill_in('sample', :with => fasta_text)
session.click_on('Submit')
And the error I was getting (with my real code, but not the code I have above) was
Warning: Unresponsive script
A script on this page may be busy, or it may have stopped responding.
You can stop the script now, open the script in the debugger, or let
the script continue.
Script: chrome://browser/content/tabbrowser.xml:2884
I wasn't running Capybara as part of a test or as part of a spec.
To confirm that the code I wrote currently has JavaScript enabled (which is something I want to disable), doing
url = "http://www.isjavascriptenabled.com"
session = Capybara::Session.new(:selenium)
session.visit(url)
indicates that JavaScript is enabled.
Capybara only uses JavaScript if you've specified a javascript_browser:
Capybara.javascript_driver = :poltergeist
And if you've specified js: true as metadata in your spec:
context "this is a test", js: true do
Check for both of those things. If they're not there and the test is not running in a browser or using Poltergeist, then it's probably not using JavaScript.