方法get(int)未定义类型Set(method get(int) is undefined for the type Set)
我写了一段逻辑,我的目标是从地图中选择随机密钥。 该地图已被指定为
ConcurrentSkipListMap<Text,IntWritable> tuples
。 另外,我对Java没有任何工业级经验,所以很难克服这个问题。这段代码是
Set<Text> keys = tuples.keySet(); String randomKeys = keys.get(random.netInt(keys.size()))
我无法找出错误语句:
method get(int) is undefined for the type Set<Text>
此外,我已经搜索了类似的问题,并且使用
List
确实存在解决方案,但我的键/值对存储为ConcurrentSkipListMap
,因此无法弄清楚这一点。谢谢。
I have written a piece of logic, where, my goal is to select random keys from the map. The map has been assigned as a
ConcurrentSkipListMap<Text,IntWritable> tuples
. Also, I don't have any industrial level experience with Java, so struggling to get over this.The piece of code is
Set<Text> keys = tuples.keySet(); String randomKeys = keys.get(random.netInt(keys.size()))
I am not able to figure out the error statement:
method get(int) is undefined for the type Set<Text>
Also, I have searched for the similar problem, and a solution do exist using
List
, but my key/value pairs are stored asConcurrentSkipListMap
, so not able to figure out this.Thanks.
原文:https://stackoverflow.com/questions/27548524
最满意答案
在XCTest中有对此功能的简写支持。
对于任何元素的第一个匹配,您可以获取所有元素并点击第一个元素:
let app = XCUIApplication() let element = app.descendentsMatchingType(.Any)["someIdentifier"] element.tap()
如果你知道它将会是什么类型的元素,最好先用这种类型进行过滤:
let app = XCUIApplication() let element = app.buttons["someIdentifier"] element.tap()
There is shorthand support for this function in XCTest.
For tapping the first match out of any element, you can get all elements and tap the first one:
let app = XCUIApplication() let element = app.descendentsMatchingType(.Any)["someIdentifier"] element.tap()
If you know what type of element it is going to be, it's better to filter by that type first:
let app = XCUIApplication() let element = app.buttons["someIdentifier"] element.tap()
相关问答
更多-
尝试直接访问你的元素... app.staticText["something"] 当我写我的UITests时,我遇到过这样的问题。 我搜索了元素,放置断点并读取输出。 使用po app命令在控制台中打印app po app 。 阅读输出,搜索你想要的元素,看看它的类型(如果是一个staticText,button,otherElements,无论...) 看到所有可用的元素都显示在输出中。 输出中每行的第一个字是每个元素的类型。 在你的代码中,访问类型使用: app.buttons按钮, app.stat ...
-
我们遇到了同样的问题。 经过一些调试后,我们发现这是由于您的应用程序启用了Background Modes引起的。 我们的解决方案是为禁用所有Background Modes开发和测试制定新的目标。 仅供参考,在项目设置的Capabilities部分中,标记为Background Modes将其Off是关键。 或者,您可以从Info.plist中删除Require background modes (又名UIBackgroundModes )键 We experienced the same issue. ...
-
您需要在Xcode中指定UI测试目标的目标应用程序。 为此,进入UI测试目标的常规设置并选择一个目标应用程序。 见下文 You need to specify in Xcode the target application of your UI Testing Target. For that go to the General settings for your UI Testing target and select a Target Application. See below
-
锤子双击功能......(Hammer double tap function …)[2024-05-01]
我不知道Hammer是什么,但是,看起来你每次双击时都会添加一个doubletap事件,这实际上是重复地将你的宽度设置为“600”然后doubletap回到“320”。 相反,只有一个侦听器,它检查宽度的当前值,并执行相应的操作: Hammer(element).on("doubletap", function(){ if(element.getAttribute("width") === "320") element.setAttribute("width", "600"); else i ... -
同样的问题 - 屏幕点是正确的,但实际的手势坐标搞砸了。 这个解决方法对我有用: class SmartXCUICoordinate { let element: XCUIElement let normalizedOffset: CGVector init(element: XCUIElement, normalizedOffset offset: CGVector) { self.element = element self.normalized ...
-
对于标题颜色,您可以轻松完成此操作,而无需添加事件。 button.setTitleColor(.white, for: .highlighted) button.setTitleColor(.black, for: .normal) 对于背景颜色,您需要定义以下事件: button.addTarget(self, action: #selector(touchDown(button:)), for: .touchDown) button.addTarget(self, action: # ...
-
用这个替换你的功能: func imageTapped(_ sender: UITapGestureRecognizer) { if let imageView = sender.view as? UIImageView { if ( imageView == photoImageViewLeft ) { print("Image1 Tapped") }else { print("Image2 Tapped") ...
-
使用XCUIApplication和覆盖窗口的OSX UI测试(OSX UI testing with XCUIApplication and covered windows)[2021-12-04]
要点击某个特定窗口之前,请执行以下操作。 [[[XCUIApplication alloc] init].windows[@"Window"] click]; To focus a specific window before clicking something inside it, do the following. [[[XCUIApplication alloc] init].windows[@"Window"] click]; -
在XCTest中有对此功能的简写支持。 对于任何元素的第一个匹配,您可以获取所有元素并点击第一个元素: let app = XCUIApplication() let element = app.descendentsMatchingType(.Any)["someIdentifier"] element.tap() 如果你知道它将会是什么类型的元素,最好先用这种类型进行过滤: let app = XCUIApplication() let element = app.buttons["someIdent ...
-
简短回答: 您无法从UITest项目访问AppDelegate文件。 答案很长: 正如奥莱哈在回答中所述 : Xcode UI测试的设计使得测试代码只能看到用户可以看到的内容,因此测试代码中不能使用或检查被测应用程序中的任何对象。 这也是为什么屏幕上的视图表示为XCUIElement对象而不是UIView后代的原因。 UI测试在与测试中的应用程序不同的可执行文件中运行。 Short answer: You can´t access you AppDelegate file from your UITest ...