Xamarin用户界面测试。控制局面';s背景色ios
我是xamarin UI测试的新手。 我需要得到UIView的颜色。据我所知,我需要使用Invoke方法,因为并没有其他测试方法可以做到这一点。我试着通过这样的方式来改变颜色Xamarin用户界面测试。控制局面';s背景色ios,xamarin,xamarin.ios,automated-tests,ui-testing,Xamarin,Xamarin.ios,Automated Tests,Ui Testing,我是xamarin UI测试的新手。 我需要得到UIView的颜色。据我所知,我需要使用Invoke方法,因为并没有其他测试方法可以做到这一点。我试着通过这样的方式来改变颜色 var color = app.Query(c => c.Marked("someText").Invoke("BackgroundColor")); 或 但是它返回的对象只有星号字符串“*******”,或者在使用“Value”时崩溃。 请告诉我我做错了什么 此外,我还因为任何错误的请求得到了“******”,例
var color = app.Query(c => c.Marked("someText").Invoke("BackgroundColor"));
或
但是它返回的对象只有星号字符串“*******”
,或者在使用“Value”
时崩溃。
请告诉我我做错了什么
此外,我还因为任何错误的请求得到了“******”,例如
var result = app.Query(x => x.Marked("Mark").Invoke("TextColorAAAAAAA"));
result = {object[1]} [0] "*****"
所以xamarin不知道命令“背景”
更新
看起来xamarin一直在等待来自small letter的命令“backgroundColor”。但这并不能解决问题。现在它返回空对象,甚至没有默认值
[0] {
red => [
],
alpha => [
],
type => [
],
blue => [
],
green => [
]
}
尝试使用
UIColor
的私有字段styleString
,如下所示:
var color = app.Query(c => c.Marked("someText").Invoke("backgroundColor").Invoke("styleString"))[0];
您应该获得一个字符串rgb值:rgb(1,2,3)
这样,您就可以解析字符串,从中提取R、G和B元素。我知道这已经很旧了,但是如果有人需要Xamarin Android的相同元素,您可以执行以下操作:
int colorValue = Convert.ToInt32(App.Query(x => x.Class("LinearLayout").Invoke("getBackground").Invoke("getColor"))[0]);
var color = Color.FromArgb(colorValue);
return color;
仍然得到带有
“****”
的字符串。看起来像是Invoke(“BackgroundColor”)
返回这种奇怪的格式,而其他操作没有结果:(@JuniorD.这很奇怪,我稍后会用我的Mac试试。@JuniorD.酷,我今天或明天会把我的Mac拿回来,并且会检查出来。你的“styleString”一切都正常
和背景色搭配downcase。非常感谢!请将您的backgroundColor
编辑为backgroundColor
,以获得完全正确的答案:)@JuniorD。很高兴终于解开了这个谜岗位固定。
int colorValue = Convert.ToInt32(App.Query(x => x.Class("LinearLayout").Invoke("getBackground").Invoke("getColor"))[0]);
var color = Color.FromArgb(colorValue);
return color;