Skip to content

Commit 08ddd4d

Browse files
committed
[dotnet] Adding support for Firefox and Chromium Android options
1 parent dc59524 commit 08ddd4d

File tree

5 files changed

+280
-0
lines changed

5 files changed

+280
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// <copyright file="ChromiumAndroidOptions.cs" company="WebDriver Committers">
2+
// Licensed to the Software Freedom Conservancy (SFC) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The SFC licenses this file
6+
// to you under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
// </copyright>
18+
19+
using OpenQA.Selenium.Internal;
20+
21+
namespace OpenQA.Selenium.Chromium
22+
{
23+
/// <summary>
24+
/// Generates the capabilities for automating Chromium applications on Android
25+
/// </summary>
26+
public class ChromiumAndroidOptions : AndroidOptions
27+
{
28+
private string androidProcess;
29+
private bool androidUseRunningApp;
30+
31+
/// <summary>
32+
/// Initializes a new instance of the <see cref="ChromiumAndroidOptions"/> class.
33+
/// </summary>
34+
/// <param name="androidPackage"></param>
35+
public ChromiumAndroidOptions(string androidPackage) : base(androidPackage)
36+
{
37+
}
38+
39+
/// <summary>
40+
/// Gets or sets a value indicating whether to use an already running app.
41+
/// </summary>
42+
public bool UseRunningApp
43+
{
44+
get { return this.androidUseRunningApp; }
45+
set { this.androidUseRunningApp = value; }
46+
}
47+
48+
/// <summary>
49+
/// Gets or sets the process name of the Activity hosting the app. If not given, it
50+
/// is assumed to be the same as <see cref="AndroidActivity"/>.
51+
/// </summary>
52+
public string AndroidProcess
53+
{
54+
get { return this.androidProcess; }
55+
set { this.androidProcess = value; }
56+
}
57+
}
58+
}

dotnet/src/webdriver/Chromium/ChromiumOptions.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public abstract class ChromiumOptions : DriverOptions
6161
private string mobileEmulationDeviceName;
6262
private ChromiumMobileEmulationDeviceSettings mobileEmulationDeviceSettings;
6363
private ChromiumPerformanceLoggingPreferences perfLoggingPreferences;
64+
private ChromiumAndroidOptions androidOptions;
6465

6566
/// <summary>
6667
/// Initializes a new instance of the <see cref="ChromiumOptions"/> class.
@@ -175,6 +176,15 @@ public ChromiumPerformanceLoggingPreferences PerformanceLoggingPreferences
175176
set { this.perfLoggingPreferences = value; }
176177
}
177178

179+
/// <summary>
180+
/// Gets or sets the options for automating Chromium applications on Android.
181+
/// </summary>
182+
public ChromiumAndroidOptions AndroidOptions
183+
{
184+
get { return this.androidOptions; }
185+
set { this.androidOptions = value; }
186+
}
187+
178188
/// <summary>
179189
/// Gets or sets a value indicating whether the <see cref="ChromiumDriver"/> instance
180190
/// should use the legacy OSS protocol dialect or a dialect compliant with the W3C
@@ -644,6 +654,11 @@ private Dictionary<string, object> BuildChromeOptionsDictionary()
644654
chromeOptions[PerformanceLoggingPreferencesChromeOption] = this.GeneratePerformanceLoggingPreferencesDictionary();
645655
}
646656

657+
if (this.androidOptions != null)
658+
{
659+
this.AddAndroidOptions(chromeOptions);
660+
}
661+
647662
if (this.windowTypes.Count > 0)
648663
{
649664
chromeOptions[WindowTypesChromeOption] = this.windowTypes;
@@ -657,6 +672,31 @@ private Dictionary<string, object> BuildChromeOptionsDictionary()
657672
return chromeOptions;
658673
}
659674

675+
private void AddAndroidOptions(Dictionary<string, object> chromeOptions)
676+
{
677+
chromeOptions["androidPackage"] = this.androidOptions.AndroidPackage;
678+
679+
if (!string.IsNullOrEmpty(this.androidOptions.AndroidDeviceSerial))
680+
{
681+
chromeOptions["androidDeviceSerial"] = this.androidOptions.AndroidDeviceSerial;
682+
}
683+
684+
if (!string.IsNullOrEmpty(this.androidOptions.AndroidActivity))
685+
{
686+
chromeOptions["androidActivity"] = this.androidOptions.AndroidActivity;
687+
}
688+
689+
if (!string.IsNullOrEmpty(this.androidOptions.AndroidProcess))
690+
{
691+
chromeOptions["androidProcess"] = this.androidOptions.AndroidProcess;
692+
}
693+
694+
if (this.androidOptions.UseRunningApp)
695+
{
696+
chromeOptions["androidUseRunningApp"] = this.androidOptions.UseRunningApp;
697+
}
698+
}
699+
660700
private Dictionary<string, object> GeneratePerformanceLoggingPreferencesDictionary()
661701
{
662702
Dictionary<string, object> perfLoggingPrefsDictionary = new Dictionary<string, object>();
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// <copyright file="FirefoxAndroidOptions.cs" company="WebDriver Committers">
2+
// Licensed to the Software Freedom Conservancy (SFC) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The SFC licenses this file
6+
// to you under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
// </copyright>
18+
19+
using System.Collections.Generic;
20+
using System.Collections.ObjectModel;
21+
using OpenQA.Selenium.Internal;
22+
23+
namespace OpenQA.Selenium.Firefox
24+
{
25+
/// <summary>
26+
/// Generates the capabilities for automating Firefox applications on Android
27+
/// </summary>
28+
public class FirefoxAndroidOptions : AndroidOptions
29+
{
30+
private string androidPackage;
31+
private string androidDeviceSerial;
32+
private string androidActivity;
33+
private List<string> androidIntentArguments = new List<string>();
34+
35+
/// <summary>
36+
/// Initializes a new instance of the <see cref="FirefoxAndroidOptions"/> class.
37+
/// </summary>
38+
/// <param name="androidPackage"></param>
39+
public FirefoxAndroidOptions(string androidPackage) : base(androidPackage)
40+
{
41+
}
42+
43+
/// <summary>
44+
/// Gets a read-only list of the intent arguments set for this set of options.
45+
/// </summary>
46+
public ReadOnlyCollection<string> AndroidIntentArguments
47+
{
48+
get { return this.androidIntentArguments.AsReadOnly(); }
49+
}
50+
51+
/// <summary>
52+
/// Argument to launch the intent with. The given intent arguments are appended to the "am start" command.
53+
/// </summary>
54+
/// <param name="arguments">The argument to add.</param>
55+
public void AddIntentArgument(string argument)
56+
{
57+
this.AddIntentArguments(argument);
58+
}
59+
60+
/// <summary>
61+
/// Arguments to launch the intent with. The given intent arguments are appended to the "am start" command.
62+
/// </summary>
63+
/// <param name="arguments">The arguments to add.</param>
64+
public void AddIntentArguments(params string[] arguments)
65+
{
66+
this.androidIntentArguments.AddRange(arguments);
67+
}
68+
}
69+
}

dotnet/src/webdriver/Firefox/FirefoxOptions.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public class FirefoxOptions : DriverOptions
7070
private Dictionary<string, object> profilePreferences = new Dictionary<string, object>();
7171
private Dictionary<string, object> additionalFirefoxOptions = new Dictionary<string, object>();
7272
private Dictionary<string, object> environmentVariables = new Dictionary<string, object>();
73+
private FirefoxAndroidOptions androidOptions;
7374

7475
/// <summary>
7576
/// Initializes a new instance of the <see cref="FirefoxOptions"/> class.
@@ -134,6 +135,15 @@ public bool EnableDevToolsProtocol
134135
set { this.enableDevToolsProtocol = value; }
135136
}
136137

138+
/// <summary>
139+
/// Gets or sets the options for automating Firefox on Android.
140+
/// </summary>
141+
public FirefoxAndroidOptions AndroidOptions
142+
{
143+
get { return this.androidOptions; }
144+
set { this.androidOptions = value; }
145+
}
146+
137147
/// <summary>
138148
/// Adds an argument to be used in launching the Firefox browser.
139149
/// </summary>
@@ -377,6 +387,11 @@ private Dictionary<string, object> GenerateFirefoxOptionsDictionary()
377387
firefoxOptions[FirefoxEnvCapability] = this.environmentVariables;
378388
}
379389

390+
if (this.androidOptions != null)
391+
{
392+
this.AddAndroidOptions(firefoxOptions);
393+
}
394+
380395
foreach (KeyValuePair<string, object> pair in this.additionalFirefoxOptions)
381396
{
382397
firefoxOptions.Add(pair.Key, pair.Value);
@@ -394,5 +409,31 @@ private void SetPreferenceValue(string preferenceName, object preferenceValue)
394409

395410
this.profilePreferences[preferenceName] = preferenceValue;
396411
}
412+
413+
private void AddAndroidOptions(Dictionary<string, object> firefoxOptions)
414+
{
415+
firefoxOptions["androidPackage"] = this.androidOptions.AndroidPackage;
416+
417+
if (!string.IsNullOrEmpty(this.androidOptions.AndroidDeviceSerial))
418+
{
419+
firefoxOptions["androidDeviceSerial"] = this.androidOptions.AndroidDeviceSerial;
420+
}
421+
422+
if (!string.IsNullOrEmpty(this.androidOptions.AndroidActivity))
423+
{
424+
firefoxOptions["androidActivity"] = this.androidOptions.AndroidActivity;
425+
}
426+
427+
if (this.androidOptions.AndroidIntentArguments.Count > 0)
428+
{
429+
List<object> args = new List<object>();
430+
foreach (string argument in this.androidOptions.AndroidIntentArguments)
431+
{
432+
args.Add(argument);
433+
}
434+
435+
firefoxOptions["androidIntentArguments"] = args;
436+
}
437+
}
397438
}
398439
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// <copyright file="AndroidOptions.cs" company="WebDriver Committers">
2+
// Licensed to the Software Freedom Conservancy (SFC) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The SFC licenses this file
6+
// to you under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
// </copyright>
18+
19+
using System;
20+
21+
namespace OpenQA.Selenium.Internal
22+
{
23+
/// <summary>
24+
/// Provides a base class for options for browsers to be automated on Android.
25+
/// </summary>
26+
public class AndroidOptions
27+
{
28+
private string androidPackage;
29+
private string androidDeviceSerial;
30+
private string androidActivity;
31+
32+
/// <summary>
33+
/// Initializes a new instance of the <see cref="AndroidOptions"/> class.
34+
/// </summary>
35+
/// <param name="androidPackage"></param>
36+
protected AndroidOptions(string androidPackage)
37+
{
38+
if (string.IsNullOrEmpty(androidPackage))
39+
{
40+
throw new ArgumentException("The Android package cannot be null or the empty string", "androidPackage");
41+
}
42+
43+
this.androidPackage = androidPackage;
44+
}
45+
46+
/// <summary>
47+
/// The package name of the application to automate.
48+
/// </summary>
49+
public string AndroidPackage
50+
{
51+
get { return this.androidPackage; }
52+
}
53+
54+
/// <summary>
55+
/// The serial number of the device on which to launch the application.
56+
/// </summary>
57+
public string AndroidDeviceSerial
58+
{
59+
get { return this.androidDeviceSerial; }
60+
set { this.androidDeviceSerial = value; }
61+
}
62+
63+
/// <summary>
64+
/// Gets or sets the name of the Activity hosting the app.
65+
/// </summary>
66+
public string AndroidActivity
67+
{
68+
get { return this.androidActivity; }
69+
set { this.androidActivity = value; }
70+
}
71+
}
72+
}

0 commit comments

Comments
 (0)