New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#106 fix: The ability to start appium server programmatically #126

Merged
merged 33 commits into from Dec 21, 2015

Conversation

Projects
None yet
2 participants
@TikhomirovSergey
Member

TikhomirovSergey commented Dec 18, 2015

Change list is below:

  • The namespace OpenQA.Selenium.Appium.Service with designed classes was added;
  • The class OpenQA.Selenium.Appium.Service.AppiumLocalService was designed. It implements OpenQA.Selenium.Remote.ICommandServer;
  • AppiumDriver and subclasses were refactored. New constructors were added.
  • almost all tests were redesigned. iOS tests are supporting iOS 8.2. Some new test were added.

Requirements

  • Installed Node.js.
  • At least an appium server instance installed via npm.

Which capabilities these features provide

Proposed features provide abilities and options of the starting of a local Appium node server. End users still able to open apps as usual

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.SetCapability(MobileCapabilityType.PlatformVersion, "6.0");
capabilities.SetCapability(MobileCapabilityType.DeviceName, "Android Emulator");
capabilities.SetCapability(MobileCapabilityType.App, app);
driver = new AndroidDriver<AppiumWebElement>(new Uri("desired remote or local URL"), capabilities, timeSpanForTheResponse);        

when the server works locally\remotely. Now they are free to launch a local Appium node server and open their app for the further testing the following way:

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.SetCapability(MobileCapabilityType.PlatformVersion, "6.0");
capabilities.SetCapability(MobileCapabilityType.DeviceName, "Android Emulator");
capabilities.SetCapability(MobileCapabilityType.App, app);
driver = new AndroidDriver<AppiumWebElement>(capabilities, timeSpanForTheResponse);        

How to prepare the local service before the starting

If there is no specific parameters then

using OpenQA.Selenium.Appium.Service;
...

AppiumLocalService service = AppiumLocalService.BuildDefaultService();
service.Start();
 ...
service.Dispose();

Requirements(!!!):

  • make sure that the path to node.js is defined at the PATH environmental variable and there is an Appium server instance installed via NPM

OR

  • please set up the NODE_BINARY_PATH environmental variable. Here should a full path to the node.js executable file. This usecase is very useful for platforms which differ from Windows. There are possible unpredictable issues related to user's environmental settings. Also it is useful then the instance of non-default (it is not defined at the PATH, it is the another node.js modification such as NSolod and so on) node.js is requred. Also it is possible to define the path to not default appium.js via APPIUM_BINARY_PATH environmental variable.

This usecase is possible to perform programmatically like:

using OpenQA.Selenium.Appium.Service;
using System;
...

Environment.SetEnvironmentVariable(AppiumServiceConstants.NodeBinaryPath, "the full path to node.js executable file");
Environment.SetEnvironmentVariable(AppiumServiceConstants.AppiumBinaryPath, "the full path to appium.js");
AppiumLocalService service = AppiumLocalService.BuildDefaultService();
service.Start();
 ...
service.Dispose();

If there should be non default parameters specified then

If non localhost IP address is requred then

using OpenQA.Selenium.Appium.Service;
...

AppiumLocalService service = new AppiumServiceBuilder().WithIPAddress("listenableIP").
                Build();
service.Start();
 ...
service.Dispose();

If the the log file is required for server output

using OpenQA.Selenium.Appium.Service;
using System.IO;
...

AppiumLocalService service = new AppiumServiceBuilder().
WithLogFile(new FileInfo("path\to\log\file")).Build();
service.Start();
 ...
service.Dispose();

If it needs for the port which differs from 4723 then

using OpenQA.Selenium.Appium.Service;
...

AppiumLocalService service = new AppiumServiceBuilder().UsingPort(4000).Build();
service.Start();
 ...
service.Dispose();

or

using OpenQA.Selenium.Appium.Service;
...

AppiumLocalService service = new AppiumServiceBuilder().UsingAnyFreePort().Build();
service.Start();
 ...
service.Dispose();

If it needs to define other server parameters then

using OpenQA.Selenium.Appium.Service;
using OpenQA.Selenium.Appium.Service.Options;
...

OptionCollector args = new OptionCollector().AddArguments(GeneralOptionList.LogNoColors());
AppiumLocalService service = new AppiumServiceBuilder().WithArguments(args).Build();
service.Start();
 ...
service.Dispose();

Actual server flags are listed here. In order to use them easyly they are listed by:

  • OpenQA.Selenium.Appium.Service.Options.GeneralOptionList - here are common server options
  • OpenQA.Selenium.Appium.Service.Options.AndroidOptionList - here are Android-specific server options
  • OpenQA.Selenium.Appium.Service.Options.IOSOptionList - here are iOS-specific server options

Boolean arguments have no parameters. Other server flags require not empty string values.

If it needs to override the default file path to node.js executable and/or the path to appium.js file then

using OpenQA.Selenium.Appium.Service;
...

AppiumLocalService service = new AppiumServiceBuilder().
WithAppiumJS(new FileInfo("the path to the desired appium.js")).
UsingDriverExecutable("the path to the desired node.js executable file").Build();
service.Start();
 ...
service.Dispose();

How to create an AppiumDriver instance

The common constructors are still available

public AppiumDriver(Uri remoteAddress, ICapabilities desiredCapabilities, TimeSpan commandTimeout)

public AppiumDriver(Uri remoteAddress, ICapabilities desiredCapabilities)

There are new constructors:

public AppiumDriver(AppiumLocalService service, ICapabilities desiredCapabilities, TimeSpan commandTimeout)

public AppiumDriver(AppiumLocalService service, ICapabilities desiredCapabilities)

public AppiumDriver(AppiumServiceBuilder builder, ICapabilities desiredCapabilities, TimeSpan commandTimeout)

public AppiumDriver(AppiumServiceBuilder builder, ICapabilities desiredCapabilities)

public AppiumDriver(ICapabilities desiredCapabilities, TimeSpan commandTimeout)

public AppiumDriver(ICapabilities desiredCapabilities)

An instance of AppiumLocalService which has passed through constructors will be stopped when

  driver.Quit();

If there is need to keep the service alive during a long time then something like that is available

  service.Start();

  ....

  new IOSDriver<AppiumWebElement>(service.ServiceUrl, capabilities, commandTimeout)

The known issue

This case can cause problems

TimeSpan timeOutOfTheWaitingForASimulator //(!!!);
...
AppiumServiceBuilder builder = new AppiumServiceBuilder();
OptionCollector collector = new OptionCollector().AddArguments(IOSOptionList.LaunchTimeout(Convert.
ToString(timeOutOfTheWaitingForASimulator.TotalMilliseconds)));
AppiumLocalService localService = builder.WithArguments(collector).Build();

  ....
TimeSpan  commandTimeout; //imagine that this timeout is much lesser than 
//timeOutOfTheWaitingForASimulator 

new IOSDriver<AppiumWebElement>(localService.ServiceUrl, capabilities, commandTimeout)
//or
//new IOSDriver<AppiumWebElement>(localService, capabilities, commandTimeout)
//here the starting of IOSDriver may be failed

So a command timeout and an iOS Simulator launching timeout should be synchronized for now.
This issue may be fixed further.

TikhomirovSergey added some commits Nov 28, 2015

#106 fix: Resources/ Work with options
- resources were added;
- work with options. The collecting of server option values
- project root name space was improved
#106 fix: IOSOptionList was added
Also comments in Russian were moved :)
#106 fix: AppiumServiceBuilder was added
also new Exceptions were created
#106 fix: Finished the setting of a service
The next step is implementation of the service building
#106 fix: Everything is implemented
...but is not tested
#106 fix: Test coverage of a service starting
AppiumLocalService has to be implemented
#106 FIX: Service was implemented
but it still needs for a bit improvement
#106 fix: Driver constructors were redesigned
The next and the final step is the redesigning of tests
#106 fix: Existing test redesign
Some new tests should be added
#106 FIX: new tests.
Also the whole suite was reorganized.
#106 fix: Improvement of the service stopping
when creation of a session is failed
#106 fix: Improvement of the server stopping
and additional test were provided

TikhomirovSergey added some commits Dec 19, 2015

#106 fix: iOS test fix.
Synchronization of the iOS simulator starting and response timeouts
@TikhomirovSergey

This comment has been minimized.

Show comment
Hide comment
@TikhomirovSergey

TikhomirovSergey Dec 21, 2015

Member

@Astro03 Can you please review this PR? :)
@Jonahss @bootstraponline you can take a look at this if it is interesting to you.

Member

TikhomirovSergey commented Dec 21, 2015

@Astro03 Can you please review this PR? :)
@Jonahss @bootstraponline you can take a look at this if it is interesting to you.

@Astro03

This comment has been minimized.

Show comment
Hide comment
@Astro03

Astro03 Dec 21, 2015

Contributor

@TikhomirovSergey I honestly don't have time to look through all 62 files but just looking from the first 15 or so, looks good. The only comment I have is that I would like DOC tags on all public methods which would be useful to developers.

Contributor

Astro03 commented Dec 21, 2015

@TikhomirovSergey I honestly don't have time to look through all 62 files but just looking from the first 15 or so, looks good. The only comment I have is that I would like DOC tags on all public methods which would be useful to developers.

TikhomirovSergey added a commit that referenced this pull request Dec 21, 2015

Merge pull request #126 from TikhomirovSergey/#106-fix
#106 fix: The ability to start appium server programmatically

@TikhomirovSergey TikhomirovSergey merged commit ce02439 into appium:master Dec 21, 2015

@TikhomirovSergey TikhomirovSergey referenced this pull request Mar 15, 2016

Merged

#138 fix #144

1 of 3 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment