Second Android Native Page focus Issue - appium

While trying to automate android native application , Appium is not identify or focus on any single element on second page of native application after automating first page login functionality successfully .I have tried with all wait method and driver. context method but it is now working .I have tried to debug the code with so many wait time but it is not working .When i put a break point after automating first page and tried to debug the application then i observed that if i put any manual action on second page (open window and close same window )then appium is allowing to identify the second page also but i didn't understand why it is happening .By automation script, i am unable to do anything on second page .Could any team help me for the same? Page source code for second page :- "
i have tried with below method for identify the second page..
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(30));
ICapabilities caps = driver.Capabilities;
String context = driver.Context;
Console.WriteLine("Current context", context);
driver.Context = ("NATIVE_APP");
String afterloginsource = driver.PageSource;
Console.WriteLine("After loginv page source :- ", afterloginsource);
TouchAction t = new TouchAction(driver);
t.Tap(100, 100).Perform();
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(2400));
String loginsource = driver.PageSource;
Console.WriteLine("Befor login page source :- ",loginsource);
driver.HideKeyboard();
//enter valid account
driver.FindElementById("com.Testing:id/userid").SendKeys("00229715");//uat02
// driver.HideKeyboard();
/////driver.FindElement(By.XPath("//android.widget.EditText[#index='1']")).SendKeys("17765919"); ////upn02
///enter valid password
driver.FindElementById("com.Testing:id/password").SendKeys("1");
///click login button
driver.FindElementById("com.Testing:id/login").Click();
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(30));
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(200));
ICapabilities caps = driver.Capabilities;
String context = driver.Context;
Console.WriteLine("Current context", context);
driver.Context = ("NATIVE_APP");
String afterloginsource = driver.PageSource;
Console.WriteLine("After loginv page source :- ", afterloginsource);
TouchAction t = new TouchAction(driver);
t.Tap(100, 100).Perform();
AndroidElement expandList = driver.FindElementById("com.Testing:id/btn_more_options");
expandList.Click(); Or //((IJavaScriptExecutor)driver).ExecuteScript("mobile: scroll", scrollObject);
//IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
//IWebElement hiddenButton = driver.FindElementById("com.Testing:id/enableNotify");
//String script = "arguments[0].click();";
//js.ExecuteScript(script, hiddenButton);
it is giving error as nosuchelement exception for any element on second page.

NoSuchElement states for inability to find the element. It strongly seems for me that xpath locators to webelements on the page are incorrect.
I do recommend to try out remote debugging just to ensure the locators are organized correctly. And using remote debugging tool - You may also check the locators on-the-fly there.
As an option B) - I could also recommend to take a quick glance towards SeeTest automation tool. The link above guide on how to set up project from scratch, and here is public documentation for SeeTest.

Related

How do I find the Conversion Action ID for use in the Google Ads API?

I'm using the latest (v7) Google Ads API to upload offline conversions for Google Ads, using the Python Client Library. This is the standard code I'm using:
import os
from google.ads.googleads.client import GoogleAdsClient
client = GoogleAdsClient.load_from_env(version='v7')
def process_adwords_conversion(
conversion_date_time,
gclid,
conversion_action_id,
conversion_value
):
conversion_date_time = convert_datetime(conversion_date_time)
customer_id = os.environ['GOOGLE_ADS_LOGIN_CUSTOMER_ID']
click_conversion = client.get_type("ClickConversion")
conversion_action_service = client.get_service("ConversionActionService")
click_conversion.conversion_action = (
conversion_action_service.conversion_action_path(
customer_id, conversion_action_id
)
)
click_conversion.gclid = gclid
click_conversion.conversion_value = float(conversion_value)
click_conversion.conversion_date_time = conversion_date_time
click_conversion.currency_code = "USD"
conversion_upload_service = client.get_service("ConversionUploadService")
request = client.get_type("UploadClickConversionsRequest")
request.customer_id = customer_id
request.conversions = [click_conversion]
request.partial_failure = True
conversion_upload_response = (
conversion_upload_service.upload_click_conversions(
request=request,
)
)
uploaded_click_conversion = conversion_upload_response.results[0]
print(conversion_upload_response)
print(
f"Uploaded conversion that occurred at "
f'"{uploaded_click_conversion.conversion_date_time}" from '
f'Google Click ID "{uploaded_click_conversion.gclid}" '
f'to "{uploaded_click_conversion.conversion_action}"'
)
return False
I believe the code is fine, but I'm having problems locating the conversion_action_id value to use. In the Google Ads UI there's a screen listing the different Conversion Actions, with no sign of an ID anywhere. You can click on the name and get more details, but still no ID:
The conversion action detail screen in Google Ads UI
I've tried the following:
Using the ocid, ctId, euid, __u, uscid, __c, subid URL parameters from this detail page as the conversion_action_id. That always gives an error:
partial_failure_error {
code: 3
message: "This customer does not have an import conversion action that matches the conversion action provided., at conversions[0].conversion_action"
details {
type_url: "type.googleapis.com/google.ads.googleads.v7.errors.GoogleAdsFailure"
value: "\n\305\001\n\003\370\006\t\022dThis customer does not have an import conversion action that matches the conversion action provided.\0320*.customers/9603123598/conversionActions/6095821\"&\022\017\n\013conversions\030\000\022\023\n\021conversion_action"
}
}
Using the standard Google answer:
https://support.google.com/google-ads/thread/1449693/where-can-we-find-google-ads-conversion-ids?hl=en
Google suggests creating a new Conversion Action and obtaining the ID in the process. Unfortunately their instructions don't correspond to the current UI version, at least for me. The sequence I follow is:
Click the + icon on the Conversion Actions page
Select "Import" as the kind of conversion I want
Select "Other data sources or CRMs" then "Track conversions from clicks"
Click "Create and Continue"
I then get the screen:
Screen following Conversion Action creation
The recommended answer says:
The conversion action is now created and you are ready to set up the tag to add it to your website. You have three options and the recommended answer in this thread is discussing the Google Tag Manager option, which is the only option that uses the Conversion ID and Conversion Label. If you do not click on the Google Tag Manager option you will not be presented with the Conversion ID and Conversion Label.
Not so! What three options? The first "Learn more" link mentions the Google Tag Manager, but in the context of collecting the GCLID, which I already have. The "three options" mentioned in the official answer have gone. Clicking "done" simply takes me back to the Conversion Actions listing.
Using the REST API
I've tried authenticating and interrogating the endpoint:
https://googleads.googleapis.com/v7/customers/9603123598/conversionActions/
hoping that would give a list of conversion actions, but it doesn't. It just gives a 404.
Does anybody know a way of getting the Conversion Action ID, either from the UI or programmatically (via client library, REST or some other method)?
Thanks!
If you're using Python, you can list your conversions via next snippet:
ads: GoogleAdsServiceClient = client.get_service('GoogleAdsService')
pages = ads.search(query="SELECT conversion_action.id, conversion_action.name FROM conversion_action", customer_id='YOUR_MCC_ID')
for page in pages:
print(page.conversion_action)
You can also open conversion action in UI and locate &ctId=, that's the conversion action id.
I found this post with the solution how to get the Conversion Action ID:
(…) I found out that conversionActionId can be found also in Google
Ads panel. When you go to conversion action details, in URL there is
parameter "ctId=123456789" which represent conversion action id.
By the way, I tried something similar and it's still not working, but with this Conversion Action ID I get a different "Partial Failure" message, at least.
At least in Google Ads API (REST) v10,
it works if field conversionAction is set with value:
'customers/{customerId}/conversionActions/{ctId}'
customerId - without hyphens
ctId - conversion action id, as mentioned in above comments,
taken from GET parameters in Google Ads panel when specific conversion is opened.
Can also be found programmatically with API method.

Block script execution in Firefox extension?

Probably looking for an answer to an age-old question, but I would like to block script execution. In my use-case blocking the browser is acceptable.
Also, in my use-case I am trying to do this from a Firefox extension, which means my code is "Chrome code", running in the browser environment.
This can easily be done by using a modal window, then programmatically closing the window. So this demonstrates that there is a blocking mechanism that exists.
Is there any way to achieve modal blocking without actually creating or opening the modal window? Some way to tap into the blocking mechanism used for modal windows?
I've done a lot of searching on this subject, but to no avail.
Using nsIProcess you can block the thread.
You can create an executable which has a sleep or usleep method or equivalent. Then run the process synchronously (nsIProcess.run) and set blocking argument to true.
Of course for portability you will need to create an executable appropriate for each platform you wish to support, and supply code for discrimination.
Basic code is something like the following. I have verified on 'nix (Mac OS X) this code to work, using a bash script with only the line sleep .03:
let testex = Components.classes["#mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsIFile);
testex.initWithPath("/Users/allasso/Desktop/pause.sh");
let process = Components.classes["#mozilla.org/process/util;1"]
.createInstance(Components.interfaces.nsIProcess);
process.init(testex);
let delay = 30; // convert this to milliseconds in the executable
process.run(true,[delay],1); // `run` method runs synchronously, first arg says to block thread
In an extension you probably would want to make your nsIFile file object more portable:
Components.utils.import("resource://gre/modules/FileUtils.jsm");
let testex = FileUtils.getFile("ProfD",["extension#moz.org","resources","pause.sh"]);
Of course keep in mind that Javascript is basically single-threaded, so unless you are blocking a thread spawned using Web Workers you will be freezing the entire UI during the sleep period (just like you would if you opened a modal window).
References:
https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIProcess
https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIFile
https://developer.mozilla.org/en-US/Add-ons/Code_snippets/File_I_O#Getting_special_files
https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/basic_usage
OPTION 1
There is enterModalState and leaveModalState in nsIDOMWindowUtils here: MDN :: nsIDOMWindowUtils Reference
However they don't seem to work for me. This topic might explain why: nsIDOMWindowUtils.isInModalState() not working they topic says isInModalState is marked [noscript] which I see, but enterModalState and leaveModalState are not marked [noscript] I have no idea why it's not working.
What does work for me though is suppressEventHandling:
var utils = Services.wm.getMostRecentWindow('navigator:browser').
QueryInterface(Components.interfaces.nsIInterfaceRequestor).
getInterface(Components.interfaces.nsIDOMWindowUtils);
utils.suppressEventHandling(true); //set arg to false to unsupress
OPTION 2
You can open a tiny window with the source window as the window you want to make modal and as dialog but open it off screen. Its dialog so it wont show a new window the OS tab bars. However hitting alt+f4 will close that win, but you can attach event listeners (or maybe use the utils.suppressEventHandling so keyboard doesnt work in it) to avoid the closing till you want it closed. Here's the code:
var sDOMWin = Services.wm.getMostRecentWindow(null);
var sa = Cc["#mozilla.org/supports-array;1"].createInstance(Ci.nsISupportsArray);
var wuri = Cc["#mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString);
wuri.data = 'about:blank';
sa.AppendElement(wuri);
let features = "chrome,modal,width=1,height=1,left=-100";
if (PrivateBrowsingUtils.permanentPrivateBrowsing || PrivateBrowsingUtils.isWindowPrivate(sDOMWin)) {
features += ",private";
} else {
features += ",non-private";
}
var XULWindow = Services.ww.openWindow(sDOMWin, 'chrome://browser/content/browser.xul', null, features, sa);
/*
XULWindow.addEventListener('load', function() {
var DOMWindow = XULWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowInternal || Ci.nsIDOMWindow);
DOMWindow.gBrowser.selectedTab.linkedBrowser.webNavigation.stop(Ci.nsIWebNavigation.STOP_ALL);
DOMWindow.gBrowser.swapBrowsersAndCloseOther(DOMWindow.gBrowser.selectedTab, aTab);
//DOMWindow.gBrowser.selectedTab = newTab;
}, false);
*/

Scanning all the links (URLs) in a website and using each of them in selenium get() method

I need to get all the URLs in a website so that I can use it to open the webpage using Selenium get() method. After opening a page I intend to fetch few data from the webpage and move on to next link.
Can you help me out with the best method for doing this and provide a sample code for the same.
There are probably other ways of doing this but this is the first way I thought of.
// Create your driver of choice
WebDriver fDriver;
fDriver = new FirefoxDriver();
// Direct the driver to the site that you want to get all the links from
fDriver.get("Site URL here...");
// Grab all the anchor tags on the page you're currently on.
List<WebElement> anchors = fDriver.findElements(By.tagName("a"));
// Create a 2nd List to hold the URLs of the anchor tags.
List<String> allURLs = new ArrayList<String>();
// Iterate through all the anchors that you got.
for (WebElement a : anchors) {
// Print out the URL of the anchor.
System.out.println(a.getAttribute("href"));
// Store the URL of the List.
allURLs.add(a.getAttribute("href"));
}
// Now just get the URL you want to use from the list...
String siteURL = allURLs.get(0);
// and enter it into the get() method of the driver.
fDriver.get(siteURL);
The 2nd part of using ALL the URLs with the get method is up to you to figure out but I think I've given you a good start. Hope it helps!

How to implement IndexDB in IOS

I am developing a mobile application using phonegap, Initially I have developed using WEBSQL but now I m planning to move it on INDEXDB. The problem is it does not have direct support on IOS , so on doing much R&D I came to know using IndexedDB Polyfil we can implement it on IOS too
http://blog.nparashuram.com/2012/10/indexeddb-example-on-cordova-phonegap.html
http://nparashuram.com/IndexedDBShim/
Can some please help me how to implement this as there are not enough documentation for this and I cannot figure out a any other solution / api except this
I have tested this on safari 5.1.7
Below is my code and Error Image
var request1 = indexedDB.open(dbName, 5);
request1.onsuccess = function (evt) {
db = request1.result;
var transaction = db.transaction(["AcceptedOrders"], "readwrite");
var objectStore = transaction.objectStore("AcceptedOrders");
for (var i in data) {
var request = objectStore.add(data[i]);
request.onsuccess = function (event) {
// alert("am again inserted")
// event.target.result == customerData[i].ssn;
};
}
};
request1.onerror = function (evt) {
alert("IndexedDB error: " + evt.target.errorCode);
};
Error Image
One blind guess
Maybe your dbName contains illegal characters for WebSQL database names. The polyfill doesn't translate your database names in any kind. So if you create a database called my-test, it would try to create a WebSQL database with the name my-test. This name is acceptable for an IndexedDB database, but in WebSQL you'll get in trouble because of the - character. So your database name has to match both, the IndexedDB and the WebSQL name conventions.
... otherwise use the debugger
You could set a break point onto your alert(...); line and use the debugger to look inside the evt object. This way you may get either more information about the error itself or more information to share with us.
To do so, enable the development menu in the Safari advanced settings, hit F10 and go to Developer > Start debugging JavaScript (something like that, my Safari is in a different language). Now open then "Scripts" tab in the developer window, select your script and set the break point by clicking on the line number. Reload the page and it should stop right in your error callback, where you can inspect the evt object.
If this doesn't help, you could get the non-minified version of the polyfill and try set some breakpoints around their open function to find the origin of this error.
You could try my open source library https://bitbucket.org/ytkyaw/ydn-db/wiki/Home. It works on iOS and Android.

SPListItem.Update and SPFile.Update fail

We are running one MOSS application as below:-
1. user use InfoPath request form to trigger workflow attached to SharePoint document library
2. all sub-sequent tasks are performed by users by InfoPath task form within SharePoint site through "Workflow Task" list (open, checkout, approve or reject) till the task completed.
3. all request form submitted could be viewed as xml file in the document library through "Explorer View"
My quesiton is why I cannot update the item located in the document library, basically open the SPListItem:-
SPSite thisSite = new SPSite("http://server")
{
SPWeb thisWeb = thisSite.OpenWeb("/web")
{
thisSite.AllowUnsafeUpdates = true;
thisWeb.AllowUnsafeUpdates = true;
SPDocumentLibrary library = (SPDocumentLibrary)thisWeb.Lists["DocLib"];
foreach (SPListItem item in library.Items)
{
SPFile file = item.File;
I tried almost all ways I could find:-
item["Customer Name"] = "123456";
item.Update();
// or item.SystemUpdate();
file.Item["Customer Name"] = "123456";
file.Update();
After each update, the value resumed when reopen or visit through the same code lines!
but when I view item properties, the "Last modified" is changed
Last modified at 6/8/2010 12:27 AM by Administrator
This do drive me cray, any help, please.
Thanks & best regards,
Leon
When you publish your form to a list, it asks you to choose the fields to be shown on that list. As you choose the item you want to update, click "Modify". Check the checkbox
at the bottom saying "Allow user to edit data in this field by using a datasheet or property page". This works for me.

Resources