Getting wState Property
To determine the state of a switch, use the wState
property of the Android Switch
object that TestComplete associates with that control. If the switch is in the "on" state, this property returns 1 or True; otherwise - 0 or False. The following example determines the state of the switch and posts it to the log:
JavaScript, JScript
function Test()
{
// Select the Android device
Mobile.SetCurrent("MyDevice");
// Obtain the required switch
var p = Mobile.Device().Process("com.example.myapp");
var Swtch = p.RootLayout("").Layout("layoutTop").Layout("layout2").Switch("switch1");
// Obtain the state of the switch
var State = Swtch.wState;
// Post the text to the log
Log.Message(State);
}
Python
def Test():
# Select the Android device
Mobile.SetCurrent("MyDevice")
# Obtain the required switch
p = Mobile.Device().Process("com.example.myapp")
Swtch = p.RootLayout("").Layout("layoutTop").Layout("layout2").Switch("switch1")
# Obtain the state of the switch
State = Swtch.wState
# Post the text to the log
Log.Message(State)
VBScript
Sub Test()
' Select the Android device
Call Mobile.SetCurrent("MyDevice")
' Obtain the required switch
Set p = Mobile.Device.Process("com.example.myapp")
Set Swtch = p.RootLayout("").Layout("layoutTop").Layout("layout2").Switch("switch1")
' Obtain the state of the switch
Set State = Swtch.wState
' Post the text to the log
Call Log.Message(State)
End Sub
DelphiScript
procedure Test();
var
p, Switch, State : OleVariant;
begin
// Select the Android device
Mobile.SetCurrent('MyDevice');
// Obtain the required switch
p := Mobile.Device.Process('com.example.myapp');
Swtch := p.RootLayout('').Layout('layoutTop').Layout('layout2').Switch('switch1');
// Obtain the state of the switch
State := Swtch.wState;
// Post the text to the log
Log.Message(State);
end;
C++Script, C#Script
function Test()
{
// Select the Android device
Mobile["SetCurrent"]("MyDevice");
// Obtain the required switch
var p = Mobile["Device"]["Process"]("com.example.myapp");
var Swtch = p["RootLayout"]("")["Layout"]("layoutTop")["Layout"]("layout2")["Switch"]("switch1");
// Obtain the state of the switch
var State = Swtch["wState"];
// Post the text to the log
Log["Message"](State);
}
Simulating Actions From Keyword Tests
This topic explains how to determine the state of the switch control in scripts. You can use the described property in keyword tests too. To do this, use the On-Screen Action or the Call Object Method operations.
See Also
Working With Android Switch Controls
wState Property (Mobile Controls)