How to reuse page_source in Appium driver queries - webdriver

I have checkForKnownExceptionScreens() function to check for all the known popup windows.
The checkForKnownExceptionScreens() performs multiple queries using Appium webdriver on various id strings. For example, it invokes multiple driver.find_elements_by_id() with different ids, it also invokes driver.find_elements_by_class_name() with different class name etc.
This results in making multiple calls to the Appium server thus to the mobile device.
To make the function efficient, I want to get get the page source XML content through driver.page_source and use the XML content within my function.
Is there a way to achieve this task?

You would have to parse that xml to find if it really contains what you need.
Easier solution would be to create a list of elements on your view and iterate trough it to see if it contains your element.
Sample (java) code:
List<AndroidElement> elementsList = driver.findElements(By.xpath(".//*"));
for(AndroidElement element : elementsList){
// check if it's your element
}

Related

How do I store a fetch response to a derived store in svelte?

I have a list of items which I consume from an own custom built API (in the example I'll use typicode) and want to display them. Additionally I want to add a client side search functionality. It is exactly like this REPL from this question.
But the given list is hardcoded, yet I can't seem to build a fetch call to get those items prior and afterwards display them. Only then can the user search and filter them.
Here is my REPL.
response.json() returns a promise, so you should await it.
Working example: https://svelte.dev/repl/a93ac2dcff584b2f8d11e430c6a96fa9?version=3.31.2

Use of struct in CAPL CANalyzer

I'm writing a piece of code to simulate some stuff of diagnostic.
I've created with CANalyzer, a panel with tons of information that need to be shown using a picklist (called combobox)
What I want to do is to create a giant array of that struct that need to be selected using the SPN combobox (the picklist) , and the other parameters of the struct/object need to populate the other elements of the panel.
Is this possible without doing a tons of SysSetVariableInt or SysSetVariableString for each element?
Before I was doing this stuff using another technique, I parse the file with all the information that are stored in a giant matrix, then I use the method "on sysvar update" on the variable associated to the SPN picklist, to get the index of that, so I search for that index in the matrix, then I use the SysSetVariableInt or others, to set the values to the elements in the panel.
To populate the picklist I've found a pretty nice method "sysSetVariableDescriptionForValue" that helps to add elements, but the problem with this method, is that if you want to change elements, you can just overwrite, and not change all...so, if in a next iteration you push less element in the picklist, you will see also the old ones.
With "sysSetVariableDescriptionForValue" you basically are writing via code, the value table of that sysvariable, and is not possible (according to Vector), be flushed, on runtime... :/
I would love to do this thing using another approach, maybe with the struct is possible...i really don't know.
Any help will be very appreciated!
Regards!
TLDR; build a tool to create a .sysvar file from a structured input (comma-separated for instance), run it, get the .sysvar file and link it to the CANalyzer configuration.
I once had to create the entire testing interface with some components of the software. We didn't have a structured release procedure, and the test environment was rebuilt every time from scratch based on the new internal software interfaces. I too had to add hundreds of variables.
My solution was to generate .sysvar files programatically outside CANalyzer. Links to the .sysvar files are symbolic in the CANalyzer configuration, meaning if a file by the right name is in the right location, that file is going to be loaded.
What I want to do is to create a giant array of that struct that need
to be selected using the SPN combobox (the picklist) , and the other
parameters of the struct/object need to populate the other elements
of the panel. Is this possible without doing a tons of
SysSetVariableInt or SysSetVariableString for each element?
Create an external script to generate the .sysvar file. In the end it is just an xml file, you may study the structure of a demo one you save. Then, import that file in the CANalyzer config. You may need to close/re-open the configuration in case the .sysvar file changes.
PROs: no need to write a complicated CAPL script and update it every time a variable changes.
CONs: you must have a source for all the information, even a simple excel sheet, with all the description and such, and you have to create a tool that accepts the input file (let's assume a .csv file) and turns it into a .xml file with .sysvar extension instead.

Algolia - WordPress - how can I get the actual query into JS variable to work with it further in the hits template?

I would like to do some interesting stuff with the hits that are being displayed based on the search query that user is not only typing into search box but actually filtering using the instant search filters. I have filter based on hierarchical events_location taxonomy. Based on what user selected I would get the info in JS variable that I can then further use to do other operations in the hits div, specifically on each hit card.
So my URL when searching updates like this:
/what-to-see/?q=&idx=sdbeta_posts_events&p=0&hFR%5Btaxonomies_hierarchical.events_calendar.lvl0%5D%5B0%5D=JUL%204&hFR%5Btaxonomies_hierarchical.events_category.lvl0%5D%5B0%5D=All&hFR%5Btaxonomies_hierarchical.events_locations.lvl0%5D%5B0%5D=Paddock%20Stage
I could potentially take the URL and extract the data from it, but I am sure there is more elegant way of working with the query.
In InstantSearch.js, the state is managed by another library called the algoliasearch-helper. Through this library you can read and write the search parameters.
The cleanest to access the helper is to build a custom widget, which is a plain object with lifecycle hooks (initial rendering and the other renderings). You can read more about custom widgets there.
Once you've accessed the helper, you can read and write with the helper API.
This can be found under search.searchParameters
So:
console.log(search.searchParameters);
Will give you whole object that you can then work with.
There is however one issue with this and that is that it works only on initial load. I was unable to make this work or get any data after starting to selecting categories. So if anyone knows how to use this so it updates after each selection please comment bellow.

Converting my existing code to PageObject design pattern with PageFactory

I'm creating tests using Selenium 2 Web Driver with C#.Net. After reading through a lot of the Selenium documentation, I am not sure if I'm followign the correct design pattern and feeling unsure on how to go about testing using PageObject design patterns.
here is my current code that I'm using on my page and its working
WaitForElement(By.CssSelector("input#ctl00_ctl00_signinControl_txtUsername")).SendKeys("abc123");
WaitForElement(By.CssSelector("input#ctl00_ctl00_signinControl_txtPassword")).SendKeys("password");
SelectElement select;
IWebElement selElement = WaitForElement(By.CssSelector("select#ctl00_ctl00_ddlGoTo"));
select = new SelectElement(selElement);
select.SelectByText("Homepage");
*<more code .....>*
also I have told that I can not use Select page element using pageFactory.
Do I need to change my code the way I have coded? any feedback would be great.
The idea of the page object pattern is to have an object that represents the page. You are essentially writing an API for how to interact with the page.
For example a login page object may have the following methods:
enterUserName(String userName);
enterPassword(String password);
clickLoginButton();
The person using the page object to interact with the page does not need to care about how selenium finds elements and interacts with them. If the id on a field changes you would just need to change the locator on the page object and would not need to change all tests that call the associated page object public method.

Dynamic element id's in WebDriver

Recently I started learning WebDriver as my client that I am working for is planning to use WebDriver for automating web applications.
I have doubts regarding how WebDriver locates the elements on webpage whose id's are dynamically changing (like changing for every login to application). Can anyone explain how we can accomplish this task with WebDriver?
Locating elements with dynamic id's can be fragile. I would rather use some visible text with for example xpath expression. My point is that in most cases the visible text is usually part of the requirements or specification of the application and id's are not. Therefore the id's are more likely to change and visible text not so.
For example to locate the username field in login form I might use xpath:
//label[.='Username']//following::input[1]
This is assuming there is a label "Username" before the input field.
I have found Firebug console function $x("xpath string") to be very useful when debugging those xpaths.
For those elements on the webpage whose ids are dynamically changing:
You can try locating the elements by their Xpath locator or CSS locator
You can find more information about the locator strategies that can be employed while using WebDriver here . Have a look at these and you would figure out the various locator strategies.
In order to understand the concept for locating dynamic elements you can have a look at the Selenium1 documents here. However pls note the api in this link is for Selenium 1. But you can use the concept and the locator strategy/api provided for the WebDriver earlier to accomplish your task
We had the same problem and we ended up using jquery selectors, especially if jquery is already available at your client-side. In the ZK framework that we use, we already have some jquery extensions so we could simply write:
assertEquals(driver.findElement(By.jq("#label:eq(0)")).getText(),"ROOT_MESSAGE");
where as the By.jq() effectively boils down to :
return (WebElement)((JavascriptExecutor)context).executeScript("return jq('" + selector + "').get(0);");
You can achieve it by using contains() method which is matched element name.
WebElement cls = (new WebDriverWait(ff, 10))
.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[#class='_54nc']/span/
span[contains(text(), 'Log Out')]")));
You can try:
https://github.com/sdl/Testy/
syntax is preaty simple:
// 1. import maven dependency
// 2. init Framework in your TestBase after initializing your driver
WebDriverConfig.init(driver);
// 3. any actions based on many many attributes
WebLocator logoutBtn = new WebLocator().setText("Log Out");
// make sure the element is rendered even after fiew seconds (5 by default)
logoutBtn.assertReady();
// or do any actions with elements
logoutBtn.click();
// more properties for selecting/testing specific element with wanted attributes
WebLocator closeIcon = new WebLocator().setClasses("close").setTitle("Close");
WebLocator minimIcon = new WebLocator().setClasses("minimize").setTitle("Minimize");

Resources