"Cached element do not exists in DOM" when run Appium with Robot Framework - appium

I'm working on automated test using Appium with Robot framework on Android device. I create schedule run on Jenkins. My test flow is entering some data in page A and submit, then switch to page B to check the result and switch to page A to enter a new data. I repeat this loop for around 10+ time. Everything works fine in around 4-5 rounds but after that there show up an error :
StaleElementReferenceException: Message: Cached element 'By.xpath:
//android.widget.TextView[#text='Limit']' do not exists in DOM anymore
The TextView is in the page A. I monitored the robot and saw that the TextView was shown up but the robot did not see it. I tried restart the device but the problem is not solved. I search through the internet and found some who facing the same issue but they use different programming language like Java or Python. I have no idea what I have to do next.
Development Tools :
Appium version: 1.21.0
Robot Framework version: 4.1.2 (Python 3.10.0 on win32)

First I do not use Robot Framework, but the code should be similar according to this https://robocorp.com/docs/languages-and-frameworks/robot-framework/try-except-finally-exception-catching-and-handling.
Second, I'm not sure if this is the best way to get around this. I think there is something you can do with the expected conditions class to get around this in a "cleaner way" but I'm not quite familiar with it enough to show/tell you. Instead what I've done is something like this...
from selenium.common.exceptions import StaleElementReferenceException
while some_limiting_factor:
try:
# logic for submitting page A, assertions for page B
except StaleElementReferenceException:
element = driver.find_element('By.xpath: //android.widget.TextView[#text='Limit']' )
As much as I want to cache elements in appium, it seems that the service itself does NOT want you to, at least not in my experience. Getting a fresh element(s) every time seems to ensure a "slow but steady" test. Hopefully someone can show me the deep appium secrets one day.

Related

Electron Remote Upgrade Issue

I have a working Electron app which I wrote about two years ago. I'm not an employee of a company, but just some guy that wrote an app that a few people use to make the world a better place. Anyway, I need to make some changes to the app but my computer crashed a while back so I downloaded my old code from Github onto my new computer and started to get to work. But immediately I found the app wouldn't work in the new 17.0.0 version of electron because the REMOTE module in Electron was deprecated and then removed in previous versions. I tried to follow the instructions here... https://www.npmjs.com/package/#electron/remote?activeTab=readme to replace REMOTE with the new #electron/remote module. I've had several problems, my most recent is:
JavaScript Error: Uncaught Exception: TypeError BrowserWindow is not a constuctor at app.createWindows (C:...\main.js:89:17).
I use the remote functionality (properties?) over 50 times in my app, including .dialogue, .getGlobal, .getCurrentWindow, and .BrowserWindow.getAllWindows
I'm not including my code here because I'm not really looking for a a coding solution (unless that's the easy/best/only thing I should do and you can give me a solution from the information I've written) but more general advice on what direction I should go to solve this problem. I'm a good programmer in a language that is not Electron, or JavaScript, or NodeJS! So, with the right instruction I can get by, but please be easy on me. (For example I get lost in the instructions for #electron/remote around the API Reference section.) Thanks for any help you can provide.
Mike
Some big changes have been made to Electron over the past couple of years, especially with the use of remote. I would hate to say it but it looks like you are in for a bit of work to get it operational again.
You will want to look at ipcMain, ipcRender and contextBridge.
The inclusion of webPreferences: {preload: ""} in your new BrowserWindow() method plus the use of the above Electron methods will place you in a good starting position for safe, quick, thread seperated code.
See Context Isolation and Inter-Process Communication for more info.
PS: If you need a quick bit of code to get you going / give you an idea then let me know.

Difference in manual execution of running app in background and runAppInBackground() using appium

While executing runAppInBackground() for Android application through Appium the app gets restarted but when executed the same manually couldn't be able to reproduce the same. I Would like to deep dive into implementation of a runAppInBackground() method to reproduce the same issue in a manual way.
You need to look behind the code of runAppInBackground
From java client side (your test code) perspective, it is a single call to Appium server:
POST "/session/:sessionId/appium/app/background"
If you continue looking into where its implemented on server side, you finish with appium-android-driver function.
In short what it does:
Get current activity and package
Press physical Home button
Wait for time you provided as argument (seconds)
Bring up back in focus based on different conditions; from the code you can understand what activity is being started
Basically its a sequence of adb shell commands, that you can run from terminal.
My guess is that step 4 you did manually may differ from what Appium is doing: different activities/arguments for activity been called

UIAutomation bringing iOS app to a consistent state

I writing JavaScript test for my iOS app. I am hoping of using Apples Profiler and UIAutomation.
1) I was wondering how can I reset the app every time I run the test. I would like to reset my app to a consistent state every time before I run a new test. Have separated my tests into few groups. Every test of the first group should start on the first screen containing a tableView and filters for sorting elements in that table should be set to a consistent state. Second group of tests should start on the Settings screen and some options/switches should be pressed in particular order for me to test the UI.
2) Also first time the app starts there is a tutorial. How can I make the app think it is freshly installed and test the tutorial feature.
Thanks for the answers
How can I make the app think it is freshly installed ?
As the iOS applications are sandboxed, the only way is to delete and re-install the app every time.
In the Illuminator framework that I wrote (which extends UIAutomation), we provide an automation bridge that allows us to send "reset" commands to the app, putting it into a known state before each test is run. This makes the testing very repeatable, even if some tests fail.
Additionally, the command line scripts can recover the test run even if the app crashes.

Selenium Web Driver Error

I'm getting a weird error while trying to click on a Capybara Element
I'm using find(:xpath,"//a[contains(text(),'Connect')]").click
(find(:xpath,"//a[contains(text(),'Connect')]").present? return true)
the error I get is:
Selenium::WebDriver::Error::MoveTargetOutOfBoundsError Exception: Element cannot be scrolled into view:javascript:void(0);
i did some research and the only solution i found is that setting the selenium version to 2.16 may fix this issue (i'm using 2.25).
anybody got an idea?
It may happen when the page being tested is not fit into the current window size. If you know such pages where usually these error happening, you may explicitly scroll down before doing the operation on such hidden elements(like click, clear etc). Here the code to explicitly scroll down the page.
In java,
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("javascript:window.scrollBy(250,350)");
From the times I used selenium webdriver to test .NET apps, I would get that error when the issue was exactly what it sounds like: It's looking for an object on the page that it cant scroll to for some reason. In my case it was because some dialogue boxes would appear without scrollbars and the driver had no way to "scroll the object into view"
Can you watch the execution of your test and see if that's the case? I had some luck rolling back to a previous version of firefox because 15+ was (as of about 2 months ago when I had the issue) unsupported by web driver and had this problem periodically. Rolling back selenium versions may help too.
First step though is definitely to watch the execution of the test and see whats happening though. And a good debugging idea may be to try to work through your steps manually yourself to make sure the test works by hand.
Its also worth noting that for the webdriver to be able to execute click the object actually has to be visible. IsPresent doesnt require that, it just searches the page files. Also an issue I ran into. IsPresent will still return true for objects that are not and cannot be made visible on the page (i.e. something at the bottom of the page that you cant see at the time)
Couple of tips here:
Webdriver should ideally be on the most recent update, it's what most use (Unless you're doing Ruby Automation)
Use css selectors, xpath (Whilst rendered), is almost always heavier on both resources and code.
Try defensive coding, first of all ascertain it exists. There are many ways to do that dependent on what package you are using. In ruby you would do page.has_css?('css_string')

Testing multiple concurrent browser sessions

I'm developing a card-game in Ruby on Rails, and trying to work out how best to test it.
When a player joins a game, their Player object is stored in the session. Obviously, in order for the game to work, I need more than one Player in a game at once. Since sessions are the same for different tabs in one browser, I'm currently testing a 2-player game by having the app open in FireFox and Internet Explorer at the same time.
Before I go off and download Chrome in order to test a third player... is there an easier way of doing this?
Edit: To clarify, I'm not yet at the stage where I want to run automated tests to see if it breaks. I'm at the stage where I want to be able to hack the back-end db, then refresh the page and see how it looks now, or click a button to see the (usually) failure response, or whether the behaviour is looking right.
You can run Firefox with multiple profiles. From a command line go to the directory Firefox is installed in and run firefox -P. Create a profile for every instance that you want to run. Close the profile manager, then for each profile run firefox -no-remote -P "profile name". You can run as many instances of Firefox as you want, and each one runs with an independent profile and thus independent session.
Automate it!
You really don't want to be manually testing this. You could use a Ruby script with the curl libs to generate the 'moves' and manage the response including the session cookie.
As a teaser, see this snippet from the API docs, sounds like it would help you..
easy.cookiejar = "cookiejar.file" => "pwd string"
Set a cookiejar file to use for this Curl::Easy instance.
This file will be used to persist cookies.
Use http://watir.com/ to create ruby scripts exercising your game.
Use multiple Watir::Browser instances to run multiple browsers.
Use firefox' profiles and -no-remote switch to keep them separated. See also this question.
Rather than opening a new tab, create a new window in your Web browser. The new window will have its own session. This works for Internet Explorer, but not for Firefox. I haven't tested it in the WebKit based browsers.

Resources