running UIAutomation script in many macs? - ios

I could create and replay the following script very well in the mac I Use.
var target = UIATarget.localTarget();
UIATarget.localTarget().delay(15);
target.frontMostApp().mainWindow().tableViews()[0].textFields()[0].tap();
When I run the above script in another mac, It shows error in the 3rd line.
after changing the above script's third line as following, it is replaying fine.
target.frontMostApp().mainWindow().tableViews()[1].textFields()[0].tap();
Just I have changed tableview's index from 0 to 1. How can I achieve this in multiple
mac systems? Both mac are having same xcode version(xcode 5) and simulator version(6.1) and mac version.Why Instruments are taking scripts API differently in different macs?

For more consistent results one of the ways can be to access AX element by name (or other identifier/expected content/number of contained cells etc.). For example here Trouble Getting Elements by Name from UIAElementArray in UIAutomation SO question and corresponding discussion about how name for element can be set in different ways.
For example:
var mainWindow = UIATarget.localTarget().frontMostApp().mainWindow();
var tableViews = mainWindow.tableViews();
tableViews['TableView'].textFields()[0].tap();
or
var mainWindow = UIATarget.localTarget().frontMostApp().mainWindow();
var tableViews = mainWindow.tableViews();
tableViews['TableView'].textFields.withName("TextFieldName")[0].tap();
If using names are not practicable can be analysed content of the table and according to that right table can be selected. For example if table has some cell with name "Cell name":
var mainWindow = UIATarget.localTarget().frontMostApp().mainWindow();
var tableViews = mainWindow.tableViews();
if (tableViews[0].cells().firstWithName("Cell name")) {
tableViews[0].textFields()[0].tap();
} else if (tableViews[1].cells().firstWithName("Cell name")) {
tableViews[1].textFields()[0].tap();
}
More details about identifying cells in tableView for example in SO question UIACollectionView cells vs visibleCells This looks not very nice but it can be reasonable workaround and should work quite reliable. If number of cells are know and different in these tables than number of cells can be compared to find required table.

Related

Playwright c# how to select one of multiple identical elements

Im using playwright with C# and a trying to do the following:
I have two elements with the same locator.
I want to be able to locate one of them by position, i.e 1st or 2nd found.
when do the following:
var nameField = page.Locator("div[data-key='Name']");
await nameField.FillAsync("");
I get the error:
Microsoft.Playwright.PlaywrightException : Error: strict mode violation: "div[data-ph-key='Name']" resolved to 2 elements:
Ive tried the following based on the playwright documentation:
var nameField = page.Locator("div[data-ph-key='Name'] >> nth=0");
this results in the element resolved to 2 elements error:
also tried this
var nameField = page.Locator("div[data-key='Name']");
await nameField.First.FillAsync("");
which returns the same error
How can do a simple select the nth element found and interact with it?
Is there something similar to selenium's IWebelements where I would put all the matching elements in a collection and interact with the desired one based on its index position?
Okay, so this works:
var nameField = page.Locator("div[data-key='Name']")
await nameField.Nth(0).FillAsync("");

Can you write a Google Sheets function that draws something?

Is it possible to write your own custom function in google sheets script that returns a drawn image, similar to how the SPARKLINE function works, except I want to make one that draws a pie chart instead.
I do not want to use Insert > Chart... > Pie Chart because that creates a floating chart on top of the spreadsheet. I would like to be able to write my own function that would return a pie chart that is embedded within the cell that the function is entered in, just like you can do with columns, bars, and line charts using sparkline.
How about following idea? This sample script embeds a chart to a cell using custom function on Spreadsheet. I think that this method is one of various ideas.
Problems :
When you want to create a chart and embed it to a cell using custom functions, you notice that insertChart() cannot be used. There are some limitations for using custom functions. But insertChart() creates floating charts. So in order to embed a chart to a cell, the function =IMAGE() is suitable for this situation. Here, setFormula() for setting =IMAGE() and DriveApp.createFile() for creating images from charts also cannot be used for custom functions.
Solution :
In order to avoid these limitations, I used Web Apps.
To use this sample script, please deploy Web Apps as follows.
On the Script Editor,
File
-> Manage Versions
-> Save New Version
Publish
-> Deploy as Web App
-> At Execute the app as, select "your account"
-> At Who has access to the app, select "Anyone, even anonymous"
-> Click "Deploy"
-> Copy "Current web app URL"
-> Click "OK"
When it deploys Web Apps, the approval required authorization can be done, simultaneously.
Sample Script :
Please copy and paste this script to a bound script of spreadsheet.
var folderId = "### Folder ID ###"; // This is a folder to save images.
var webappsurl = "https://script.google.com/macros/s/######/exec"; // Here, please put "Current web app URL".
function embedChart(range) {
var ac = SpreadsheetApp.getActiveSheet().getActiveCell();
var q1 = "?datarange=" + range;
var q2 = "&row=" + ac.getRow();
var q3 = "&col=" + ac.getColumn();
var url = webappsurl + q1 + q2 + q3;
UrlFetchApp.fetch(url);
}
function doGet(e) {
var sheet = SpreadsheetApp.getActiveSheet();
var chart = sheet.newChart()
.setChartType(Charts.ChartType.PIE)
.addRange(sheet.getRange(e.parameters.datarange))
.setOption('height', 280)
.setOption('width', 480)
.setOption('title', 'Sample chart')
.build();
var file = DriveApp.getFolderById(folderId).createFile(
chart.getAs('image/png').setName("chart_image.png")
);
file.setSharing(DriveApp.Access.ANYONE_WITH_LINK, DriveApp.Permission.VIEW);
sheet.getRange(e.parameters.row, e.parameters.col).setFormula(
'=IMAGE("' + "http://drive.google.com/uc?id=" + file.getId() + '")'
);
}
Flow of Script :
embedChart()
Input =embedChart("a2:a6") in cell B7.
Using fetch(), sends data of a2:a6 and the inputted coordinate to doGet().
doGet()
Using doGet(), get the data.
Creates a chart using inputted range a2:a6. (in this case, creates a pie chart)
Saves a chart as an image. (in this case, saves as PNG)
Updates a permission of the image file to use for =IMAGE().
Embeds the image using =IMAGE() which was imported by setFormula().
Result :
By inputting =embedChart("a2:a6") in cell B7 as a custom function, following result can be obtained.
Note :
When the custom function embedChart() is used, loading time is about 40 seconds. (I don't know whether this occurs at only my environment.)
Permissions of the created image are ANYONE_WITH_LINK, VIEW.
embedChart() is overwritten by =IMAGE(). So when the spreadsheet is reopened, the response of =IMAGE() is much faster than that of embedChart().
If I misunderstand your question, I'm sorry.

Open/Libre Office macro to scroll view to selection

In Writer, I would like to search for some text and when found position the view to the top of the view/window.
Using the following code,
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args1(1) as new com.sun.star.beans.PropertyValue
args1(0).Name = "SearchItem.SearchString"
args1(0).Value = ":"
dispatcher.executeDispatch(document, ".uno:ExecuteSearch", "", 0, args1())
the view changes and it shows the selection but it is not in any particular place. I want it to be at the top of the window/view.
I've also found elsewhere the use of ThisComponent.currentController.getViewData() and restoreViewData(). So I experimented and determined how to change the data returned in order to get a vertical scroll but nothing happens. For example...
vd = ThisComponent.currentController.getViewData()
vdParts = Split(vd, ";")
vdParts(6) = CLng(vdParts(6)) + 1000
vd = join(vdParts, ";")
ThisComponent.currentController.restoreViewData(vd)
Any suggestions?
PS: I am running version 5.0.5.2 on Windows 7 x64
Spreadsheets have View Panes that can be manipulated, but it does not look like there is a similar interface in Writer.
Instead, use the View Cursor to go down one or two pages, then move back to the location of the search result.
Also, do not use the dispatcher for the search. Use the API instead, like in section 7.14 of Andrew Pitonyak's macro document.

how do you iterate through elements in UI testing in Swift/iOS?

I understand how I could, for example look at one element in a table, but what's the correct way to simply iterate through all the elements, however many are found, to for example tap on them?
let indexFromTheQuery = tables.staticTexts.elementBoundByIndex(2)
Okay I succeeded in figuring out the simple syntax. I have just started working with Swift and so it took me sleeping on it to think of the answer.
This code works:
var elementLabels = [String]()
for i in 0..<tables.staticTexts.count {
elementLabels.append (tables.staticTexts.elementBoundByIndex(i).label)
}
print (elementLabels)
My guess is the answer is there is no way to do so.
The reason is because of my experience with one of the critical iOS components while making a number of UI tests: UIDatePicker.
If you record a test where you get the page up and then you spin the picker, you will notice that the commands are all non-specific and are screen related. In the case of the picker, however, community requests resulted in the addition of a method for doing tests: How to select a picker view item in an iOS UI test in Xcode?.
Maybe you can add a helper method to whatever controller contains this table. Also, keep in mind that you can easily add methods without polluting the class interface by defining them as extensions that are in test scope only.
For Xcode 11.2.1, SwiftUI and swift 5 based app, the following code works for testing a list, each element in this case appears as a button in the test code. The table is set up like this (for each row) :
NavigationLink(destination: TopicDetail(name: "Topic name", longDesc: "A description")) {
TopicRow(thisTopic: top).accessibility(identifier: "newTopicRow_\(top.name!)")
}
Then I catch the members of the table by getting the buttons into an array:
let myTable = app.tables.matching(identifier: "newTopicTable")
var elementLabels = [String]()
for i in 0..<myTable.buttons.count {
elementLabels.append (tablesQuery.buttons.element(boundBy: i).label)
}
print (elementLabels)
Finally, I deleted each member of the table by selecting the detail view where I have a delete button, again with
.accessibility(identifier: "deleteTopic"
I wanted to delete all members of the table:
for topicLabel in elementLabels {
let myButton = app.buttons[topicLabel]
myButton.firstMatch.tap()
app.buttons["deleteTopic"].tap()
}

Tab Groups - Any API

Is there any way to use the high-level APIs to detect whether a tab is in the active Panorama group? It seems there's no mention of the tab group a tab belongs to in the tabs module, at least.
Currently there are no plans to provide a tab group api - the 'panorama' feature in Firefox has not proved to be very popular, so there may not be much benefit vs focusing on other features.
Actually there is a way.
I don't know how to get the XUL tab with the SDK, but I know it's possible as I recall people posting questions that did this. Maybe #canuckistani you can help us get the xul tab.
Anyways once you have the tab then you can access it's property _tabViewTabItem. And from here you can do whatever you want. Like figure out the group id of the tab by going tab._tabViewTabItem.parent.id Or change group id's.
Here is some code, the first two lines are non-sdk code.
var tab = gBrowser.tabContainer.childNodes[10]; //non sdk code
gBrowser.selectedTab = tab; //non sdk code
console.log(tab._tabViewTabItem.parent.id) //works both in sdk and non-sdk
Note: pinned tabs dont have the _tabViewTabItem property. So thats how you can tell if its pinned.
var tabs = gBrowser.tabContainer.childNodes;
for (var i=0; i<tabs.length; i++) {
try {
console.log(tabs[i]._tabViewTabItem.parent.id);
} catch(ex) {
console.warn('tab ' + i + ' ex:', ex);
console.log('its probably pinned')
}
}
The Tab Groups extension stores it's data using SessionStore.
var tabData = JSON.parse(SessionStore.getTabValue(tab,"tabview-tab"));
console.log(tabData.groupID); // 3
Data about the groups themselves is stored on the browser.xul object (ie. ownerGlobal). Data specific to each group is stored as "tabview-group" and other data is stored as "tabview-groups".
var groupsData = JSON.parse(SessionStore.getWindowValue(tab.ownerGlobal, 'tabview-groups'));
console.log(groupsData); // Object { nextID: 4,
activeGroupId: 3,
activeGroupName: "Third Group",
totalNumber: 2 }
var groupData = JSON.parse(SessionStore.getWindowValue(tab.ownerGlobal, 'tabview-group'));
console.log(tabData[3].title); // Third Group

Resources