Not able to create FirefoxDriver instance in a servlet - java

I had created a java application for selenium webdriver.
FirefoxDriver driverff= new FirefoxDriver();
used to create a new Firefox instance.
This is working fine.
I want to create a java web application to do the same.
I have embeded the same code in the servlet class in the doget() method and it throws
java.lang.NoClassDefFoundError: org/openqa/selenium/firefox/FirefoxDriver
Can someone tell me how i can fix this?
From an end to end perspective, what oi want to achieve is that a web page (done using servlets) has some buttons which when clicked need to open a selenium web driver and run the selenium scripts. I am assuming the java application for web-driver can be called using servlet.
If there is some other alternative to achieve this, please do suggest.

The error message means that Java can't find the class in question. Make sure it's on the classpath of your web app.
That said, you may run into problems later: Linux web servers often don't have an attached display so no X server is running. That will make it hard to start a browser :-) If that's the case for you, look up Google for "selenium xvnc" or "selenium headless"

Related

How to attach a chrome window to a desktop application Selenium?

My problem is when I click on a desktop icon, it opens a link in already opened chrome browser in a new tab. How do I attach with the already opened browser and not a new one?
The below code returns a null because there is no window opened through selenium ofcourse, so yeah.
Set<String> windows = webdriver.getWindowHandles();
System.out.println(windows);
Any suggestions would be of great help. Thanks In advance.
There is no way to attach the chrome window that you've opened from the desktop application to your WebDriver instance.
If you want to be able to control a web page with a Selenium - you must pass your URL to a driver like that:
webdriver.get("https://www.your_link.com");
You might think about the way of getting and storing your URL as a variable and passing it into your code.
That would also be helpful if you add a bit more details about the problem. It's a bit unclear at what stage of the test you open the web page with a desktop application. Selenium can't be used to test desktop applications. Code sample of the test from your project would also help.

Java - Go to new url in new window/tab

I want to be able to use Java to tell it to go to X url when X browser is open/running (my lingo is terrible). (Firefox/Chrome/IE is already up, and I want it to go from the default page to let's say Twitter.)
Most of the solutions are using java.awt.Desktop to launch native browser with a url in it, but that isn't useful if I want to change the url later on. (Already on Twitter-Home Page, but want to go to Twitter-Contact Us afterwards.)
The other solutions I've seen involve using Selenium WebDriver, but I also need to eventually learn how to basically force the Java to read a long list of URLs off an excel and simply verify that url isn't dead, and then do this on the Native Android browser, for example. So the Selenium might not be the right choice. Granted, you can also tell me this is an awesome choice for this too if it truly is. I haven't really been exploring Selenium.
Sorry for asking such a basic question. Company wants QA Automation without training/hiring an Automation QA. My end goal (aside not getting canned), is to see if I can get a bunch of urls to load on specific browsers. I can sort of (praying) be able to do stuff with it afterwards.
A simple trick would be to create an add-on( if you know javascript ) which will be quite similar in chrome and firefox (for IE I have no idea in my days it needed BHO) and send websocket commands from java to your addon. But this needs a java websocket server running where your addon will connect when the browser opens. Rest of communication can be carried upon the protocol lines of your requirements.
There are multiple parts to your question.
Read urls from excel.
Use Apache POI to do the same. Selenium code can use the same.
Check that the urls are not dead.
Use any java http client, (apache) to do that without even opening a browser. If the link is dead, it will be dead for all the browser.
Open the links in a multiple browsers.
Selenium is perfect for this. I am assuming that after the page is loaded you have way of validating that the page is correct. Selenium is very powerful here.
Target native android browser too.
I do not know of much difference between this and the previous question unless you are also testing site display based on browser size. The browser is more or less the same as chrome with webkit rendering engine.

Headless Selenium test which fills out a form?

We have a terminal application which serves webcontent via iFrames to our clients.
For some reason, it has been decided that we want to automate the test for this server side. I need to visit a page, fill out a form, and submit it - without actually rendering it in a GUI, I believe a headless selenium driver can do this - but I am new to selenium, does anyone have an example of how to do this in java with selenium?
You can use PhantomJS. Here you can find a working example.

How to get browser window front while running the test using selenium webdriver?

I'm currently running my selenium webdriver tests in 2 browsers (studentdriver and tutordriver)
studentdriver = new ChromeDriver();# opening student in chrome browser
tutordriver = new FrefoxDriver();#opening tutor with firefox browser
and I'm student browser first and then tutorbrowser soth that student browser will be behind and tutorbrowser will be on front side. when script running with studentbrowser, it will automatically comes fron and tutorbrowser will be back side but when script start running using tutorbrowser it is not coming front side and it is creating some problem in between.
I need a solution to get tutorbrowser front when script start running on tutorbrowser.
Note: I should not close studentbrowser because I'm closing both the browsers in #After
((JavascriptExecutor) driver).executeScript("window.focus();");
try this with each driver.
Unfortunatly, this is an OS problem. It's up to the window manager to handle the ovelapping, tiling, organisation of the windows, which you can't control directly from your code.
The best bet you'll have is to launch a Sikuli Robot with which you'll be able to bring back the correct window. It's a bit of work, though, to include in your tests, but it can be used from Java with no problem
See the beast at http://www.sikuli.org

Does init support apps with Selenium Jars?

Is it possible to embed a Java app that has Selenium code lines into a web browser? Is this supported or not?
I have a Java application that uses Selenium API. I tried to use the init() method to embed the GUI window into a browser so that the application could be launched from a website, however it did not work. Is it supposed to be this way?
Technically you can because the selenium java client is just an java app that interacts with selenium grid in JsonWire protocol.
Take a look at this question Run selenium webdrivers from applet in HTML
No it does not. You cannot launch such an app from a web browser

Categories

Resources