Ruby Appium assert - ruby

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

Related

Selenium-webdriver in Ruby crashes when element is not found

When looking at a dynamic element on a webpage, Selenium crashes if the element is not present. As a result I'm having to rescue the application to continue. I figure I'm doing something wrong with the syntax
response = driver.find_element(:class, element).text
If the element is not found, Selenium errors and crashes the application. This happens regardless of my browser configuration.
Selenium is not crashing. Your code has encountered an exceptional condition (attempting to work with an element that is not there). The code is correctly responding to that exceptional condition by raising a NoSuchElementError.
If you are trying to determine if an element is there, you can use Driver#find_elements and check if the Array#size equals 0.
If you are trying to work with an element that is not yet on the page, you'll need to create an explicit wait to poll for the element to show up as in DebanjanB's answer.
You need to wait a bit for the element to be visible before you try to locate it as follows:
wait = Selenium::WebDriver::Wait.new(:timeout => 10)
ele = wait.until { driver.find_element(:class, element).displayed? }
response = ele.text

Wait until element has disappeared in Cypress

please, tell me what methods to use to wait for a loading screen element to disappear? PS. I'm not using an API request.
I tried to use two methods, but it doesn't work properly:
1. cy.get('#loading', { timeout: 30000 }).should('not.be.visible');
I get the error: -- Timed out retrying after 30000ms: Expected to find element: #loading, but never found it.
2. Used plugin (cypress-wait-until) like so cy.waitUntil(() => {document.querySelector('#loading') === null};
This approach doesn't find the element at all.
If you are trying to retrieve an element that is not in the DOM, use not.exist instead:
cy.get('#loading').should('not.exist');
In cases where you do need to wait, you can try using cy.wait:
An example use case for this might be if Cypress has to route to your page first and you want to ensure the page loads before you start testing:
cy.wait(200);

Cypress - How to Wait for an attribute value to be false in Cypress

I have a website which has everything in an iFrame. My scripts are failing because cypress is not able to wait for loading bar as cypress does not support iframes as of now. I want to write a custom command which wait until attributes 'ng-reflect-loading' value is changed to false.
I have tried with below code but its not working and halts cypress runner. Reference Thread 136
cy.get('iframe').iframeLoaded().its('document').getInDocument('.main >ng-component > :nth-child(1)').then(function($loading) {
while( $loading.attr('ng-reflect-loading')!='false')
{
cy.log('waiting')
}
})
Can anyone please help on this.
I don't have any insight of how iFrames work. But is 'ng-reflect-loading' eventually hidden?
In that case this check should work:
cy.get('.ng-reflect-loading')
.should('not.exist')
If it remains existing but the value should change you could either check on the first value not existing:
cy.get('.ng-reflect-loading')
.should('not.contain.attr', 'attr_name', 'first value')
Or if the value changes, you could check for the second value to be available:
cy.get('.ng-reflect-loading')
.should('contain.attr', 'attr_name', 'second value')

Appium test not going any further after Splash Screen

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?

Don't run a cucumber feature if a element on the page is not available but exit without failing

I want to check a page for an element before I start running the feature file for it (It's an element that periodically appears with an event so I only want to run the feature if its present).
The approach I wanted to use was a tagged before hook to see if the element was present and if it wasn't just don't run the feature but exit without 'failing' the step just exit with a message. I tried variants on the below but
1. If I don't have a rescue clause it obviously fails the scenario when the element isn't present
2. If I do have the rescue clause it handles it and passes moving onto the features which will then fail as the event isn't available.
Is there a way to halt running the feature file if the rescue clause is invoked without the 'fail'?
Before('#event') do
begin
find('.event').visible?
rescue Capybara::ElementNotFound
puts 'THE EVENT IS NOT ON'
end
end
You shouldn't be using find if you want to make a decision based on existence. Instead you should be using the predicate methods provided by Capybara (has_selector?, has_css?, has_xpath?, etc) so you don't have to rescue exceptions.
The other thing to know is the Cucumber skip_this_sceanrio method, which means you should end up with something like
Before('#event') do
# visit '/some_page' # May not be needed if you have another `Before` already visiting the needed page
skip_this_scenario('Skipping due to missing event') unless page.has_css?('.event')
end

Resources