I'm try to use selenium-server-standalone-2.33.0.jar with opera and need to change some profile preferences.
It possible to create OperaProfile object in C# project and using it like this:
OperaProfile profile = new OperaProfile(); // Error: Type or namespace 'OperaProfile' could not be found
profile.preferences().set("User Prefs", "Ignore Unrequested Popups", false);
DesiredCapabilities capabilities = DesiredCapabilities.Opera();
capabilities.SetCapability("opera.profile", profile);
IWebDriver driver = new RemoteWebDriver(new Uri("http://host:4444/wd/hub"), capabilities);
In this case I got error message
Type or namespace 'OperaProfile' could not be found
Assuming you are on Windows:
The Operadriver is written in Java and not suported directly in C#, as it is mainatined not by the Selenium project team but by Opera.
To use it, you have to run the standalone Selenium webserver (from console on windows) before starting the test. get it here
you need to set the OPERA_PATH to point to your opera.exe file. Start the server with the command:
java -jar selenium-server-standalone-2.33.0.jar
i use a small bat for these two tasks:
SET OPERA_PATH="C:\Progra~2\Opera\opera.exe"
cd C:\pathToSeleniumJarFile
C:\Progra~2\Java\jre7\bin\java.exe -jar selenium-server-standalone-2.33.0.jar
C#:
testing with remotewebdriver object in your C# code to connect to it.
switch (WebBrowser)
{
case Browser.Chrome:
// chromedriver.exe has to be in the debug folder
ChromeOptions chrome = new ChromeOptions();
chrome.AddArguments("--ignore-certificate-errors");
webDriver = new ChromeDriver(chrome);
break;
...
case Browser.Opera:
//note: set OPERA_PATH environment variable (in cmd or global)
DesiredCapabilities opera = DesiredCapabilities.Opera();
opera.SetCapability("opera.profile", #"C:\OperaProfile");
webDriver = new RemoteWebDriver(opera);
break;
default:
throw new NotImplementedException();
if you want to manipulate the profile of the opera client (e.g. to accept untrusted certificates etc) you need to set
opera.SetCapability("opera.profile", #"C:\OperaProfile");
Copy an existing Profile to a location of your choice, here C:\OperaProfile.
==> Avoid spaces in all the pathes <==
Related
I have the next requirement:
Execute multiple instances(parallel) with using different chrome profile.
I have 3 profiles:
profile1, profile2 and profile3
When I create the driver i add the path of the profile1
For running in parallel, how can I tell to the second instance that use the profile 2
I found this, i can't figure out how to execute in parallel.(I'm using Nunit for parallel execution)
using the same chrome profile (session) for different ChromeDriver instances
public static IWebDriver GetDriver()
{
var options = new ChromeOptions();
options.AddArguments("--noerrdialogs");
options.AddArguments(#"user-data-dir=C:\Users\" + loggedInUser + #"\AppData\Local\Google\Chrome\profile1");
return new ChromeDriver(options);
}
Good Q. Working on same myself. To point Selenium to correct profile, so far I have the following (not complete - but part way; think there is better way; I can't open to drivers with same executable path, but can define multiple chrome drivers that pt. to same executable and then add arguments with separate profiles to each of those...(I'm using Python, you'll need to find out equivalent for Java).
from selenium import webdriver
from selenium.webdriver.chrome.webdriver import WebDriver
Options = webdriver.ChromeOptions()
Profile_Path = "C:/Users//AppData/Local/Google/Chrome/User Data/Profile/"
'''i.e. relevant path to profile in question'''
Options.add_argument('--user-data-dir=' + Profile_Path)
'''I'm experimenting with the map function to pass list of chromedrivers to a function with a loop that does something like this:'''
def SetUp(Number_Drivers):
v_profiles = []; v_options = []; v_chromedrivers =[]; v_drivers = []
profile_path = "C:/Users/..../User Data/Profile"
'''put path of profile, noting this will become Profile1, Profile2, etc. below...'''
chromedrv_path = "C:/Users/... '''(i.e. path to chromedriver)'''
for i in range(Number_Drivers):
v_profiles.append(profile_path + str(i) + "/")
v_options.append(webdriver.ChromeOptions())
v_chromedrivers.append(chromedrv_path)
v_options[i].add_argument('--user-data-dir=' + v_profiles[i]
''' v_options[i].add_argument to be included for each other argument you want to
add, e.g. '--restore-last-session', '--disable-notifications', '--disable-
search-geolocation-disclosure' etc.)'''
v_drivers.append(webdriver.Chrome(executable_path=v_chromedrivers[i], options=v_options[i])
That's as far as I am - good luck!
I am trying to learn how to write automated web tests in SauceLabs, and Visual Studio is telling me that DesiredCapabilities is deprecated in Selenium 3. I figured out how to use ChromeOptions for desktop tests, but what about mobile web tests? This works:
DesiredCapabilities caps = new DesiredCapabilities();
caps.SetCapability("deviceName", "iPhone 8 Simulator");
caps.SetCapability("deviceOrientation", "portrait");
caps.SetCapability("platformVersion", "12.0");
caps.SetCapability("platformName", "iOS");
caps.SetCapability("browserName", "Safari");
caps.SetCapability("username", SauceUsername);
caps.SetCapability("accessKey", SauceAccessKey);
caps.SetCapability("name", TestContext.TestName);
_driver = new RemoteWebDriver(new Uri("http://ondemand.saucelabs.com:80/wd/hub"),
caps, TimeSpan.FromSeconds(600));
But I don't want to use a deprecated class. I've used Selenium exensively in the past, but this my first time doing mobile web tests (no apps, just Safari/mobile Chrome). Should I be using an Appium Driver instead?
There will be a AppiumOptions() in a future release of Appium v4 that will replace this. You can pull it down now and give it a try.
It will look something like this:
public void SimpleTest()
{
var appiumOptions = new AppiumOptions();
appiumOptions.AddAdditionalCapability(MobileCapabilityType.PlatformName, "Android");
appiumOptions.AddAdditionalCapability(MobileCapabilityType.PlatformVersion, "7.1.1");
appiumOptions.AddAdditionalCapability(MobileCapabilityType.FullReset, true);
appiumOptions.AddAdditionalCapability(MobileCapabilityType.NewCommandTimeout, 60);
appiumOptions.AddAdditionalCapability("testobject_api_key", "0D6C044F19D0442BA1E11C3FF087F6A6");
appiumOptions.AddAdditionalCapability("username", SauceUser.Name);
appiumOptions.AddAdditionalCapability("accessKey", SauceUser.AccessKey);
//TODO first you must upload an app to Test Object so that you get your app key
var rdcUrl = "https://us1.appium.testobject.com/wd/hub";
var driver = new AndroidDriver<IWebElement>(new Uri(rdcUrl), appiumOptions);
driver.Navigate().GoToUrl("https://www.ultimateqa.com");
Console.WriteLine("");
driver.Quit();
}
I think you should try this with appium driver. Just download appium c# client and start. You can use following link to start with.
http://appium.io/docs/en/writing-running-appium/web/mobile-web/
For the past 2 days, I've been trying to find a way to start Chrome with a different profile but to no avail.
No matter what I do, the profile that Selenium loads for chrome is always some temporary profile like "C:\Users\DARKBO~1\AppData\Local\Temp\scoped_dir14308_25046\Default"
I have tried the following code:
ChromeOptions options = new ChromeOptions();
options.AddArgument(#"user-data-dir=C:\SeleniumProfiles\Default");
IWebDriver driver = new ChromeDriver();
driver.Navigate().GoToUrl("chrome://version");
First I tried using the directories for the profiles directly from the Chrome folder, didn't work. Then I created a new folder and moved the profiles there, I've tried doing this both in C:\ and in D:\ . No difference whatsoever.
I've tried running the user-data-dir argument both like it currently is in the code and with -- in front of it. I've tried using double backslashes without the # symbol, still nothing. No matter what I do the profile directory is always the Selenium temp directory.
P.S. The current C:\SeleniumProfiles directory I created through the command prompt using the chrome user-data-dir=C:\SeleniumProfiles command
P.S. 2: My mistake was very simple, I forgot to put the options in the constructor of the new driver. And as Tarun made it clear, user-data-dir only gives Chrome the directory that contains the profiles, then we need to use profile-directory argument to give the subdirectory that contains the needed profile.
You din't use the options objects at all.
IWebDriver driver = new ChromeDriver();
Should be
IWebDriver driver = new ChromeDriver(options);
Edit-1 - Chrome profiles and users
Chrome has User data directory for storing profiles. Inside this directory multiple profiles can be maintained. There are two arguments that can be used
user-data-directory
profile-directory
If only user-data-directory is specified then a Default directory inside the same would be used. If profile-directory is specified then that directory inside the user-data-directory is used
If you are starting with the profile of the browser on the computer you are looking for, you can
Open normal google chrome and go to ('chrome://version')
enter link description here
Copy the Profile Path but take all of the "Data" folder and copy it to where the program is running
C# Coding:
https://rextester.com/INK23784
By creating a folder named "profile" where the program is running, you can add all the profile information, plugins, and so on. etc. We have copied the data folder in everything and when opening the browser "ChromeOptions" to selenium your profile files, etc. that's everything
You can try this code: (It worked for me)
string path_profile = #"D:\PROJECT_XMARKETING_4.0\Profiles\1";
// string path_profile = #"D:\PROJECT_XMARKETING_4.0\Profiles2\2";
IWebDriver _webDriver;
ChromeDriverService cService = ChromeDriverService.CreateDefaultService();
cService.HideCommandPromptWindow = true;
_webDriver = new ChromeDriver(cService);
_webDriver.Manage().Cookies.DeleteAllCookies();
ChromeOptions options = new ChromeOptions();
options.AddArgument($"user-data-dir={path_profile}");
_webDriver = new ChromeDriver(cService, options);
//_webDriver.Navigate().GoToUrl("https://phamtani.com/");
//_webDriver.Navigate().GoToUrl("https://alink.vn/");
//_webDriver.Navigate().GoToUrl("http://api.hostip.info/get_json.php");
Set user-data-dir to C:\Users[your-username]\AppData\Local\Google\Chrome\User Data
Full Code:
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
private IWebDriver _driver { set; get; }
public YourConstructor()
{
_driver = CreateBrowserDriver();
}
private IWebDriver CreateBrowserDriver()
{
try
{
var options = new ChromeOptions();
options.AddArgument("test-type");
options.AddArgument("--ignore-certificate-errors");
options.AddArgument("no-sandbox");
options.AddArgument("disable-infobars");
//options.AddArgument("--headless"); //hide browser
options.AddArgument("--start-maximized");
//options.AddArgument("--window-size=1100,300");
//options.AddUserProfilePreference("profile.default_content_setting_values.images", 2);
// Profile [Change:User name]
options.AddArgument(#"user-data-dir=C:\Users\Haddad\AppData\Local\Google\Chrome\User Data");
var service = ChromeDriverService.CreateDefaultService();
service.HideCommandPromptWindow = true;
service.SuppressInitialDiagnosticInformation = true;
return new ChromeDriver(service, options);
}
catch
{
throw new Exception("Error: Chrome is not installed.");
}
}
When I create an instance of the Firefox Web driver, it successfully opens Firefox. However, it opens it with two tabs (one "regular" Firefox tab and one IE tab; the IE tab is active and remains active for the duration of the testing unless I manually switch to the tab that the test is actually executing in).
It will run the test in the Firefox tab (i.e. the non-active one).
I'm instantiating my Firefox web driver like this:
var firefoxOptions = new FirefoxOptions()
{
Profile = new FirefoxProfile(),
UseLegacyImplementation = false,
BrowserExecutableLocation = #"C:\Program Files (x86)\Mozilla Firefox\Firefox.exe"
};
firefoxDriver = new FirefoxDriver(firefoxOptions);
firefoxDriver.Manage().Timeouts().ImplicitWait = new TimeSpan(0, 0, 10);
I'd include the code for the unit test, too, but the problem occurs during initialization prior to me running any tests.
Also, when I do cleanup like this:
[TestCleanup]
public void Cleanup()
{
if (firefoxDriver != null)
{
firefoxDriver.Close();
firefoxDriver.Dispose();
}
}
it closes the tab that the test was running in (the Firefox tab). However, it only closes that tab - the IE tab and the browser both stay open.
This question seems to be somewhat related, but the behavior's somewhat different because Selenium isn't trying to actually execute the test in both tabs - it only ever uses the one tab. Also, the OP there was using Firefox 20.0 and I'm using Firefox 52.2.0.
Simply, we can create profile and use it. I answered here Firefox 44.0.1 opening two tabs , when running selenium webdriver code
Another way, we can create profile pro-grammatically like
FirefoxProfile profile= new FirefoxProfile();
profile.setPreference(“browser.startup.homepage”,”https://...");
WebDriver driver = new FirefoxDriver(profile);
Just use about:config in firefox URL , it will provide settings.
I'm using Selenium RC + .Net Client Driver. I've created a Firefox profile in my c:\selenium\ directory. Here's my code:
Dim MySelenium As ISelenium = Nothing
MySelenium = New DefaultSelenium("localhost", 4444, "*custom C:/Program Files/Mozilla Firefox/firefox.exe -profile c:/selenium/", "http://www.google.com/")
When I run this, I get the following error:
Failed to start new browser session: Error while launching browser
What is the proper way to do this?
You need to launch it via RC rather than in your code.
So you would do
java -jar selenium-server.jar -firefoxProfileTemplate c:\selenium\
to launch the browser and then do
Dim MySelenium As ISelenium = Nothing
MySelenium = New DefaultSelenium("localhost", 4444, "*firefox", "http://www.google.com/")
and that should launch Firefox for with the profile you want.
In Java you can create the Selenium Server programmatically and pass a File as the newFirefoxProfileTemplate configuration property:
RemoteControlConfiguration rcc = new RemoteControlConfiguration();
rcc.setPort(5499);
rcc.setFirefoxProfileTemplate(newFirefoxProfileTemplate); // This is a File object
SeleniumServer server = new SeleniumServer(rcc);
server.start();
Perhaps there are similar (or the same) vb.net classes available.