Session commands in Appium
Create New Session
Create a new session.
The server should attempt to create a session that most closely matches the desired and required capabilities.
DriverOptions cap = new AppiumOptions();
//Samsing galaxy S9 emulator –Native app
string appPath = @”C:\ADB\ApiDemos-debug.apk”;
cap.AddAdditionalCapability(MobileCapabilityType.DeviceName, “Samsung Galaxy S9”);
cap.AddAdditionalCapability(MobileCapabilityType.PlatformName, “Android”);
cap.AddAdditionalCapability(MobileCapabilityType.PlatformVersion, “8.0.0”);
cap.AddAdditionalCapability(MobileCapabilityType.Udid, “192.168.219.103:5555”);
cap.AddAdditionalCapability(MobileCapabilityType.App, appPath);
//cap.AddAdditionalCapability(“appPackage”, “io.appium.andriod.apis”);
driver = new AndroidDriver(new Uri(“http://127.0.0.1:4723/wd/hub”), cap, TimeSpan.FromSeconds(60));
String sessionId = driver.SessionId().toString(); //Get the sessionid
End Session
End the running session
driver.Quit();
Get Session Capabilities
Retrieve the capabilities of the specified session
ICapabilities caps = driver.Capabilities;
Go Back
Navigate backwards in the browser history, if possible (Web context only)
driver.Navigate().Back();
Take Screenshot
Take a screenshot of the current viewport/window/page
Screenshot screenshot = driver.GetScreenshot();
Get Page Source
Get the current application hierarchy XML (app) or page source (web)
string pageSource = driver.PageSource;
Set Timeouts
Configure the amount of time that a particular type of operation can execute for before they are aborted.
The types of timeouts are ‘page load’, ‘script’ and ‘implicit’. (The example usage is just ‘page load’)
driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(30);
Get available log types
Get available log types as a list of strings.
IReadOnlyCollection<> logTypes = driver.Manage().Logs.AvailableLogTypes;
Get Logs
Get the log for a given log type. Log buffer is reset after each request.
ILogs logs = driver.Manage().Logs;