I am trying to create a simple automation task. For now I want to log in to the webpage. This all works fine when I run the test in Visual Studio 2017. However this will need to be executed as an exe on regular interval in windows system. When I run the executable it hangs after displaying:
Starting ChromeDriver 2.32.498550 (9dec58e66c31bcc53a9ce3c7226f0c1c5810906a)
on port 9515
Only local connections are allowed.
I understand this is just info not an error per most SO posts related to this issue such as - When running WebDriver with Chrome browser, getting message, "Only local connections are allowed" even though browser launches properly
(note: my browser does not launch)
How do I run the test code as an executable?
Do I have to write additional code to invoke the test when running as executable?
Nuget Version Info
namespace RevuSeleniumAutomation
{
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.PhantomJS;
using System;
[TestClass]
public class RevuAutomater
{
private string baseURL = "http://example.com/";
private RemoteWebDriver driver;
private string browser;
public TestContext TestContext { get; set; }
[TestMethod]
[TestCategory("Selenium")]
[Priority(1)]
[Owner("Chrome")]
public void AutomateSite()
{
driver = new ChromeDriver();
driver.Manage().Window.Maximize();
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(30));
driver.Navigate().GoToUrl(this.baseURL);
driver.FindElementById("UserName").SendKeys("user");
driver.FindElementById("Password").SendKeys("12345");
}
[TestCleanup()]
public void MyTestCleanup()
{
driver.Quit();
}
[TestInitialize()]
public void MyTestInitialize()
{
}
}
}
The cmd window message after launching exe
Thank you for your time.
To run as EXE I think there are two options:
1) not with selenium server or grid
. you need package the chromedriver.exe with your code into the EXE
. you code need to calculate the path of chromedriver.exe in runtime, because you don't know user will put the EXE in which folder
. specify chromedriver.exe by ChromeOptions to tell selenium where to find it when create driver instance
Shortage of this way: a chromedriver.exe of certian version support limited chrome verions, not all chrome verions, you need to tell user which chrome the EXE support.
2) use selenium server/grid
. you code need accept selenium server/grid address from a config file which user can modify it
. create RemoteWebDriver instance with above address, not ChromeDriver in code
. no need to package chromedriver.exe with your code
Shortage of this way: A selenium server/grid need be ready before execute EXE,
But your code no need to consider the compatibility of chrome and chromedriver.exe, because they had been considered when setup selenium server/grid.
Related
Can someone point me to a website or information that discusses how to setup Selenium and write automated scripts? I need to write scripts to test a web based application. I know how to use Java and would like to do that approach.
Thanks
From the description, it looks like you want to automate the MS Edge (Chromium) browser using Selenium web driver.
I suggest you refer to the steps below.
Download the Java binding of Selenium 4.0.0-beta-1 from here.
Download the matching version of Microsoft Edge Driver from this page.
Create a new JAVA project and try to add a reference to the Java binding files by Right-click the project folder-> Build path-> Configure Build path-> Libraries tab-> Add External JARs.
Add the code below to your JAVA project.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.edge.EdgeOptions;
public class test {
public static void main(String[] args)
{
System.setProperty("webdriver.edge.driver", "Edge_web_driver_path_here....\\msedgedriver.exe"); //Modify path here...
EdgeOptions edgeOptions = new EdgeOptions();
//edgeOptions.addArguments("-inprivate");
WebDriver driver = new EdgeDriver(edgeOptions);
driver.get("https://Website_URL_here..."); //Modify URL here...
//--------------------------------------
//Your_Automation_code_here....
//--------------------------------------
driver.quit();
}
}
Run the code.
Output:
Further, you can try to modify the code example as per your requirements.
There is an existing question for the same problem but that question was not completely answered, so posting new question.
I am new to selenium and trying to execute the very basic script, but getting the compilation errors. I am using Eclipse Oxygen 4.7.2 and Selenium 3.8.1. I have added all the necessary Jar files and used the Geckodriver as well, still i am getting errors. Below are the error messages in the console window:
**"Exception in thread "main" java.lang.Error: Unresolved compilation problems:
package automationFramework;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class FirstTestCase {
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
System.setProperty("Webdriver.gecko.driver","C:\\Users\\vermap6\\Downloads\\geckodriver-v0.19.0-win64\\geckodriver.exe");
// Create a new instance of the Firefox driver
WebDriver driver = new FirefoxDriver();
//Launch the Online Store Website
driver.get("http://www.google.com");
// Print a Log In message to the screen
System.out.println("Successfully opened the website www.google.com");
//Wait for 5 Sec
Thread.sleep(5000);
// Close the driver
driver.quit();
}
}
WebDriver cannot be resolved to a type
FirefoxDriver cannot be resolved to a type"**
Can anybody tell me what mistake i am doing ? Attaching screenshots. Webdriver Error.png JAr Files in Selenium 3.8.1
The problem is about file permission. I guess you are using Mac or Linux and the default permission of the library doesn't allow Eclipse to read it. What you need is going to the directory in Terminal and then use sudo chmod to change the permission.
sudo chmod -R 755 ./
Then you may need to restart Eclipse.
I am trying to automate in Microsoft edge browser. I referred to the below links to do it and I am able to launch the browser, but it's failing to launch the URL. Can someone please help me.
Selenium Java version : 2.53.1
Tried with both of the edge drivers(insider version and webdriver), one returned null exception and not launching any browser and the other is returning unknown error after launching the browser.
https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
Code referred from:
stackoverflow.com/questions/31991309/selenium-on-windows-10-edge-browser
You would need to download the correct version of Edge Driver based on the OS build number. I faced this issue when I used Edge driver version which was different from my build number.
Follow the below steps (I have tried this with Selenium 3.0 Beta1 and its working fine)
Use the steps given below -
Go to Start > Settings > System > About and note down the OS Build number
Download the proper version of the driver from this link - https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
If the file that's downloaded is .msi, then install it to get the .exe driver. For one of the release, direct .exe can be downloaded.
Once the MicrosoftWebDriver.exe is downloaded, we can use it in our test script using either System.setProperty("webdriver.edge.driver", "driver location") or using environment variable
Sample Script :
System.setProperty("webdriver.edge.driver","C:\\Program Files (x86)\\Microsoft Web Driver\\MicrosoftWebDriver.exe"); //put actual location
WebDriver driver = new EdgeDriver();
driver.get("your link");
Refer this article for detailed information: http://automationtestinghub.com/selenium-3-launch-microsoft-edge-with-microsoftwebdriver/
Note : Edge browser version should be 18 or 19
This solution worked for me was by enabling Developer Mode in Windows OS:
Go to Settings -> Windows Update settings ->For Developers -> Enable Developer Mode
Run Test Script :
public class IETest {
public static void main(String[] args)
{`enter code here`
WebDriver obj=new EdgeDriver();;
obj.navigate().to("http://www.google.com");
}
}
I am trying to write a selenium test with fluintlenium and for some reason when I try using the chrome driver it just open chrome on "data;" page and doesn't continue to the actual url I give it.
When I use HtmlUnitDriver it runs the test successfully but with chrome it just stuck after :
Starting ChromeDriver 2.15.322448 (****) on port 36888
Only local connections are allowed.
I know its just an information message but it doesnt continue after that just stuck it doesn't show any errors...
The code is:
public class IntegrationTest extends FluentTest {
public WebDriver driver;
#Override
public WebDriver getDefaultDriver() {
driver = new ChromeDriver();
return driver;
}
/**
* add your integration test here
*/
#Test
public void title_of_bing_should_contain_search_query_name() {
goTo("http://www.bing.com");
fill("#sb_form_q").with("FluentLenium");
submit("#sb_form_go");
assertThat(title()).contains("FluentLenium");
}
}
I tried using selenium's driver.get("url"); but its not working either .
EDIT : How I run the tests? 1. I just start my selenium server 2. I use play so I run the command play test OR 2. I use eclipse junit test runner to run a single test.
Both doesn't work ...
It doesn't mean the chromedriver is not launched. It's just an information message that you can connect to it only locally.
If the browser opened and not doing anything further, in your case it means you have not compatible chrome and chrome driver. If your chrome is the latest one, then 2.13 chromedriver is too old for you, try 2.15
I get an error:
The file Capabilities [BrowserName=, IsJavaScriptEnabled=False, Platform=Any, Version=]\IEDriverServer.exe does not exist. The driver can be downloaded at http://code.google.com/p/selenium/downloads/list`
What must I do to solve this error because really I can't find information ....
Unless you're building the Selenium project from sources, or are using the .NET bindings and have set a specific option in the InternetExplorerOptions class, you shouldn't be seeing this message. The current source code is volatile in this particular area, as the project is currently implementing the usage of a standalone executable server for the IE driver, similar to what happens currently for the Chrome driver. If you are building from source, or are interested in using this new functionality, you should download the standalone IE driver server executable from the URL specified in the exception's message.
Download the IEDriver.exe for the given URL
http://code.google.com/p/selenium/downloads/list
Assuming the exe file is saved in E:\IEdriver.exe.
In Selenium you have to set the property of IEDriver, since Selenium has only firefox driver with it.
Set the system property and then invoke the IEDriver.
WebDriver driver;
System.setProperty("webdriver.ie.driver", "E:\\IEdriver.exe");
//Selenium will not support single slash, so we are providing double slash in path.
driver = new InternetExplorerDriver();
// By this it will call the IEDriver and execute
Thanks
An example to share:
public static void main(String[] args) {
System.setProperty("webdriver.ie.driver", "D:\\selenium\\IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver();
driver.get("www.google.com");
driver.findElement(By.id("gbqfq")).sendKeys("abc");
driver.close();
}
}