2

I'm trying to set the emulator system time to a predefined date every time i run the test cases. I've found the command adb shell date --set= which changes time but couldn't implement it using appium API's.

Any help in figuring out how to implement it or other alternatives is much appreciated.

I've also opened a thread on appium discuss for the same.

Naman
  • 27,789
  • 26
  • 218
  • 353

2 Answers2

2

In Ruby, i'm doing the following for avds:

  # set time using adb shell command
  # defaults to Time.now
  # mm == month, mn == minute
  # Note: formatting must include leading zeros for single character results
  def self.android_set_time(yy = Time.now.strftime('%y'),
                       yyyy = Time.now.strftime('%Y'),
                       mm = Time.now.strftime('%m'),
                       dd = Time.now.strftime('%e'),
                       hh = Time.now.strftime('%H'),
                       mn = Time.now.strftime('%M'))

    version = driver_attributes[:caps][:platformVersion].to_f

    if version >= 6.0
      system("adb shell 'date #{mm}#{dd}#{hh}#{mn}#{yy}.00'")
    else
      system("adb shell date -s '#{yyyy}#{mm}#{dd}.#{hh}#{mn}00'")
    end
  end

Note: you must use Kernel.system vs Kernel.exec.

Kernel.exec # Replaces the current process by running the given external _command_... Kernel.system # Executes _command..._ in a subshell.

Unknown if it works in saucelabs or not.

rhy
  • 106
  • 1
  • 6
1

There is currently no way to do this in Appium. It has not been implemented as an endpoint, and Appium does not allow ad hoc adb command execution, for security reasons.