selenium RC ,WebDriver driver = new RemoteWebDriver(new URL(serverUrl), capability); - selenium

See this code:
String serverUrl = "http://127.0.0.1:4444/wd/hub";
DesiredCapabilities capability = DesiredCapabilities.chrome();
capability.setJavascriptEnabled(true);
WebDriver driver = new RemoteWebDriver(new URL(serverUrl), capability);
When a request comes in, it will be create new instance, which will take between 2 and 4 seconds. For me, this is too long. How can I make it faster?

You are doing the right thing .You can increase number of nodes and browsers that will help in executing all of your tests in less time .

Related

The method implicitlyWait(long, TimeUnit) from the type WebDriver.Timeouts is deprecated what is that Mean really?

[enter image description here][1]
please resolve issue , please update the same
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(());
driver.get("https://accounts.google.com/signin");
driver.manage().window().maximize();
You can use like this :
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("https://accounts.google.com/signin");
driver.manage().window().maximize();
If you are using selenium 4 try this:
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
driver.manage().timeouts().scriptTimeout(Duration.ofSeconds(30));
driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(60));
Deprecated
It means the method implicitlyWait(long, TimeUnit) is no more supported and you should use an updated method to serve the same purpose.
You can change your code to
long time = 2000;
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(time));
Instead of arguments (long, TimeUnit), this method now takes arguments as Duration.ofSeconds(time)

getWindowHandles in selenium is always returning size as 1 even though multiple instances of chrome are open

I have multiple chrome windows open, but getWindowHandles in selenium is always returning size as 1 even though multiple instances of chrome are open.
here is the code:
System.setProperty("webdriver.chrome.driver", "C:/Downloads/New folder/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.google.com/");
driver = new ChromeDriver();
driver.get("https://www.rediffmail.com/");
driver = new ChromeDriver();
driver.get("https://www.facebook.com/");
Set<String> ids = driver.getWindowHandles();
System.out.println(ids.size());
System.out.println(ids);
and here is the output:
1
[CDwindow-DBDAD89956F46A4DE6DC3F16E70D79A6]
any idea as to why this is happening?
or perhaps maybe im doing something incorrectly.
Im using Selenium-Java "selenium-java-3.13.0"
JDK "10.0.2"
Chrome "Version 68.0.3440.75 (Official Build) (64-bit)"
getWindowHandles() method will return the set of window handles of the current WebDriver instance.
Here you are creating different instance of each url and trying to get the WindowHandles. So, it is returning the size as 1.
Instance 1:
WebDriver driver = new ChromeDriver();
driver.get("https://www.google.com/")
Instance 2:
driver = new ChromeDriver();
driver.get("https://www.rediffmail.com/");
Instance 3:
driver = new ChromeDriver();
driver.get("https://www.facebook.com/");
you are finding the windowhandles after creating the instance 3. So, the driver object will hold the instance 3 and hence driver.getWindowHandles(); is returning as 1 .
You can try by opening multiple different tab using the same driver object and then check the size of the WindowHandles.
For the understanding purpose, Please add the below steps after the instance 3 and you can observe the getWindowHandles size.
//Latest driver instance is passed
JavascriptExecutor js=(JavascriptExecutor)driver;
String url1="https://www.rediffmail.com/";
String url2="https://www.google.com/";
js.executeScript("window.open(arguments[0])",url1); //New Tab will be opened
js.executeScript("window.open(arguments[0])",url2); //New Tab will be opened
Set<String> ids = driver.getWindowHandles();
System.out.println(ids.size());
System.out.println(ids);
Output:
3
First of all we required to find how many windows are open for this required to store getWindowHandles in String as below and hope below code will helps.
Try below code
Set<String> allWindowHandles = driver.getWindowHandles();
int count = allWindowHandles.size();
System.out.println("Number of browser windows opened on the system is : "+ count);
for (String windowHandle : allWindowHandles) {
//switch to each browser window
driver.switchTo().window(windowHandle);
String title = driver.getTitle();
//print the window handle id of each browser window
System.out.println("Window handle id of page -->"+ title +" --> is : "+windowHandle);
}

How to configure and setup HTMLUNIT with Selenium while using it in C#?

I setup selenium remote driver and run the selenium server.The selenium server running correctly and while I try to run my code using :
var remoteServer = new Uri("http://127.0.0.1:4444/wd/hub");
DesiredCapabilities desiredCapabilities = DesiredCapabilities.Firefox();
desiredCapabilities.IsJavaScriptEnabled = true;
myDriver = new RemoteWebDriver(remoteServer, desiredCapabilities, new TimeSpan(0,1, 30));
No error throws in the CMD log and elements can find properly, but headache comes while I try to run this using the below code :
var remoteServer = new Uri("http://127.0.0.1:4444/wd/hub");
DesiredCapabilities desiredCapabilities = DesiredCapabilities.HtmlUnit();
desiredCapabilities.IsJavaScriptEnabled = true;
myDriver = new RemoteWebDriver(remoteServer, desiredCapabilities, new TimeSpan(0, 1, 30));
in log it throws lots of error and while I try to find any element, timeout exception showing in log.
My test code is in below :
myDriver.Manage().Window.Maximize();
myDriver.Navigate().GoToUrl(tollFreeURL);
IWebElement planClick = myDriver.FindElement(By.ClassName("trial"));
planClick.Click();
IWebElement startPlan = myDriver.FindElement(By.Id("choose2000"));
startPlan.Click();
IWebElement selectValue = myDriver.FindElement(By.Name("AreaCode"));
var selectElement = new SelectElement(selectValue);
selectElement.SelectByValue("800");
IWebElement selectNumber = myDriver.FindElement(By.XPath("//*[#id='divList']/div[1]"));
tollFreeNumber = selectNumber.Text;
tollFreeNumber = stringConvert.StringRefiner(tollFreeNumber, " ");
tollFreeNumber = stringConvert.StringRefiner(tollFreeNumber, "(");
tollFreeNumber = stringConvert.StringRefiner(tollFreeNumber, ")");
tollFreeNumber = stringConvert.StringRefiner(tollFreeNumber, "-");
Console.WriteLine(tollFreeNumber);
My target is to run the application in background and generate data, so I do not have any option to run this using Firefox.HTMLUNIT is the only option for me.Help needed it will stuck me last 3-4 days.
I believe your machine is using proxy servers. Try by adding that proxy configuration while creating driver instance.
String PROXY = "xx.xx.xx.xx:8080";
OpenQA.Selenium.Proxy proxy = new OpenQA.Selenium.Proxy();
proxy.HttpProxy=PROXY;
proxy.FtpProxy=PROXY;
proxy.SslProxy=PROXY;
Add proxy setting to desired Capabilities:
desiredCapabilities.SetCapability(CapabilityType.PROXY, proxy);

Selenium remote webdriver doesn't accept desiredCapabilities

I am trying to launch a operaDriver using remoteWebdriver, and my code is:
static private IWebDriver driver;
DesiredCapabilities capability = DesiredCapabilities.Opera();
driver = new RemoteWebDriver("http://localhost:9515", capability);
however this gives me error of RemoteDriver has invalid arguments, and it specifies RemoteDriver takes OpenQA.Selenium.ICapabilities type as argument, which is violated in my code.
I am confused here. Could anyone please share some lights?
Thank you very much!
I think you can try this
It is as in java. You can try a URL class in C#
grid_url = new URL("http://localhost:9515/wd/hub");
driver = new RemoteWebDriver(grid_url, capability);

how would I run Selenium test through the GRID using C#

i have just set-up the selenium grid on my local machine and everything seems to be up and running.
my question is, is there a way I can run the test case from selenium grid node (command prompt)?
I am using WebDriver for creating my testcase using .Net
Sample code from here
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
// Requires reference to WebDriver.Support.dll
using OpenQA.Selenium.Support.UI;
class GoogleSuggest
{
static void Main(string[] args)
{
// Create a new instance of the Firefox driver.
// Notice that the remainder of the code relies on the interface,
// not the implementation.
// Further note that other drivers (InternetExplorerDriver,
// ChromeDriver, etc.) will require further configuration
// before this example will work. See the wiki pages for the
// individual drivers at http://code.google.com/p/selenium/wiki
// for further information.
WebDriver driver = new RemoteWebDriver(new Uri("http://127.0.0.1:4444/wd/hub"),
DesiredCapabilities.FirefoxDriver());
//Notice navigation is slightly different than the Java version
//This is because 'get' is a keyword in C#
driver.Navigate().GoToUrl("http://www.google.com/");
// Find the text input element by its name
IWebElement query = driver.FindElement(By.Name("q"));
// Enter something to search for
query.SendKeys("Cheese");
// Now submit the form. WebDriver will find the form for us from the element
query.Submit();
// Google's search is rendered dynamically with JavaScript.
// Wait for the page to load, timeout after 10 seconds
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.Until((d) => { return d.Title.ToLower().StartsWith("cheese"); });
// Should see: "Cheese - Google Search"
System.Console.WriteLine("Page title is: " + driver.Title);
//Close the browser
driver.Quit();
}
}
WebDriver driver = new RemoteWebDriver(new Uri("http://127.0.0.1:4444/wd/hub"),
DesiredCapabilities.FirefoxDriver());
OR in c#
IWebDriver driver;
DesiredCapabilities capability = new DesiredCapabilities();
driver = new RemoteWebDriver(
new Uri("http://hub-cloud.com/wd/hub/"), capability);
driver.Navigate().GoToUrl("http://www.google.com");