I am trying to run a portion of code in Google Chrome and the rest in Firefox
public class flip
{
static WebDriver driver = new FirefoxDriver(); // starting firefox
public static void main(String[] args) throws IOException, InterruptedException
{
System.setProperty("webdriver.chrome.driver", "C:/chromedriver.exe");
WebDriver driver1 = new ChromeDriver();
driver1.get("website1");
driver1.findElement(By.id("id_username")).sendKeys("username");
driver1.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver1.findElement(By.id("id_password")).sendKeys("password");
System.out.print("logged in");
driver1.close();
driver.get("website-2"); // in firefox
}
}
I am getting following error (when program need to switch browsers).
Both browsers are opening but unable to drive.
Exception in thread "main" org.openqa.selenium.WebDriverException:
f.QueryInterface is not a function
Command duration or timeout: 60.03 seconds
Can any one help me where I made mistake ??
(firefox webdriver must be a static..)
put http:// on starting of your web address of your firefox driver. it is obligation in that selenium version.
Related
I have implement two scenario outlines in one feature file at cucumber, and also wrote script that new browser initiate in #After Junit command when my test case fail.
#After
public void teardownpatientregis(Scenario s) throws IOException, InterruptedException
{
if(s.isFailed())
{
Screenshots.getscreenshot(s);
driver.quit();
initialize(failbrowser);
url(failurl);
Logintestpage.getusername(failuser);
Logintestpage.getpassword(failpass);
Logintestpage.loginalert();
Thread.sleep(2000);
Logintestpage.logout();
driver.quit();
}
}
But the new Webdriver does not initiate after close my browser. It shows SessionNotCreatedException errors. Please help me to resolve this issue
The new Webdriver does not initiate after closing the browser because you are NOT closing the browser, you are issuing a quit instead.
Replace at least the first driver.quit() with driver.close()if not both of them.
Inside main method if I write WebDriver driver = new FirefoxDriver(); and execute the class how does the browser gets open automatically
public class Web{
public Static void main(String[] args){
WebDriver driver = new FirefoxDriver();
}
}
Firefox driver is included in the selenium-server-stanalone.jar available in the downloads. The driver comes in the form of an xpi (firefox extension) which is added to the firefox profile when you start a new instance of FirefoxDriver.
You can read up more on the Firefox Driver here.
If I misunderstood the question and you want to know how to open a browser and go to a URL, the below example will open the Firefox browser and go to http://www.google.com/
public class Web{
public Static void main(String[] args){
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");
}
}
Selenium has quite extensive documentation on WebDriver available here. I suggest you read the documentation to get to know Selenium better!
I've been struggling with this for the past few hours. I'm trying to install Selenium web driver and have been running into a bunch of errors which prevent me from running the test page. I'm pretty sure my most recent issue is with this code:
public static void main(String[] args) throws InterruptedException{
System.setProperty("webdriver.gecko.driver","C:/Users/theone/Downloads/geckodriver 2.exe");
Would really appreciate any feedback on second steps!
package automationFramework;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class FirstTestCase {
public static void main(String[] args) throws InterruptedException{
System.setProperty("webdriver.gecko.driver","C:/Users/theone/Downloads/geckodriver 2.exe");
// Create a new instance of the Firefox driver
WebDriver driver = new FirefoxDriver();
//Launch the Online Store Website
driver.get("http://www.store.demoqa.com");
// Print a Log In message to the screen
System.out.println("Successfully opened the website www.Store.Demoqa.com");
//Wait for 5 Sec
Thread.sleep(5);
// Close the driver
driver.quit();
}
}
You can setup Selenium with GeckoDriver either with webdriver.gecko.driver property or using environment properties. It would be good if you the latest version of Firefox, GeckoDriver and Selenium 3.0
Check out this article which provides setup using both these ways -
http://automationtestinghub.com/selenium-3-0-launch-firefox-with-geckodriver/
C:/Users/theone/Downloads/geckodriver 2.exe
There's a space in the path, it may work if you rename your file geckodriver2.exe.
I am working on writing an automation script to test a website login. Through Firefox IDE, I have written TestCase steps, it is executing fine. I exported the test case as java code compatible with jUnit 4.
When i try to run the java code via Eclipse (with firefox browser), either it opens Mozilla homepage or blank page or proxy issue (if my machine is connected to company LAN).
I am using Selenium 2.44 and Firefox version 44..
Also i read in some websites saying about compatible version of firefox with selenium web driver. I am confused a lot regarding this.
Please let me know which version of Selenium Web driver, Firefox & Java is preferred..!!!
Adding my java code below
public class Firefox {
private WebDriver driver;
private String PROXY = "proxy address:port";
private String baseUrl;
private boolean acceptNextAlert = true;
#Before
public void setUp() throws Exception {
// Code for setting up Firefox proxy
Proxy proxy = new org.openqa.selenium.Proxy();
proxy.setHttpProxy(PROXY)
.setFtpProxy(PROXY)
.setSslProxy(PROXY);
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(CapabilityType.PROXY, proxy);
driver = new FirefoxDriver(cap);
baseUrl = "url";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
#Test
public void testFirefox() throws Exception {
driver.get(baseUrl);
for (int second = 0;; second++) {
if (second >= 60) fail("timeout");
try {
if ("".equals(driver.findElement(By.id("userId")).getText())) break;
}
catch (Exception e) {}
Thread.sleep(1000);
}
driver.findElement(By.id("userId")).sendKeys("user name");
driver.findElement(By.id("pwd")).sendKeys("password");
driver.findElement(By.id("sign-in")).click();
}
}
Latest stable compatible configuration which i've found and I am using it is selenium Webdriver 2.48.2 and Firefox 41.0.2
Download Firefox ESR from https://www.mozilla.org/en-US/firefox/organizations/all/
Its stable version browser of Firefox compatible with Webdriver 2.48.2.
Selenium WebDriver 2.48.2 will not work with FF 44.
The latest Firefox always works with the latest version of Selenium (2.x versions) for all non-native events, such as JavascriptExecutor events, but there are some native events (such as driver.navigate.to() and driver.click() that won't work except with the last known native supported version of Firefox, which was 31.6.0 ESR. It's possible that later versions of ESR will work, but I have not read that anywhere.
I am trying to run some automated tests on IE11 using Selenium Webdriver. Whenever I run my code the URL that IE tries to load is http://--port=38198/
I am trying to simply load Google and return the title, then I will move onto the actual automated testing I intend to do.
Here is a sample of my code so far;
private WebDriver driver;
private String baseUrl;
#Before
public void setUp() throws Exception{
System.setProperty("webdriver.ie.driver", "C:\\Program Files\\Internet Explorer\\iexplore.exe");
DesiredCapabilities cap = DesiredCapabilities.internetExplorer();
cap.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
baseUrl = "http//www.google.com";
driver = new InternetExplorerDriver(cap);
driver.manage().deleteAllCookies();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
#Test
public void test() throws Exception{
driver.get(baseUrl);
System.out.println(driver.getTitle());
//driver.navigate().to(baseUrl);
}
Ever time I run my code it always opens the same URL - http://--port=
From my code I can't see where I have gone wrong. I changed the security settings on IE to medium and disabled protected mode (I have tried it with protected mode turned on and still no luck). I have also downloaded and installed Microsofts IE11 web driver.
I am totally mystified by this, can someone give me any insight into this...
It seems that you are using your native Windows IE?
You have to download the IE WebDriver from https://code.google.com/p/selenium/wiki/InternetExplorerDriver and your webdriver.ie.driver property needs the path to the downloaded IEDriverServer.exe
Please try and report if that solves your problem. If not I will change my chrome WebDriver to the IE and try it myself :)