I have recorded a scenario in Selenium IDE and exported it as a Junit4 Webdriver backed code.
There is a command which uses selenium object and the same thing could be done by driver object.
So I am not able to understand which one to use and when
E.g :
selenium.click("id=gen_info") can also be implemented by
driver.findElement(By.id("gen_info")).click();
Yes I do have a option to have a driver object of specific web browser but then the same thing could be done by using selenium object also.
I suppose that by selenium click u mean something like this:
WebDriver driver = new FirefoxDriver();
Selenium selenium = new WebDriverBackedSelenium(driver, baseUrl);
WebDriverBackedSelenium allows those who have test suites using the Selenium-RC to migrate to WebDriver. However it doesn't implement all methods.
In this particular case it should work the same, though WebDriverBacked may be slower
Related
I am creating testing of my website in pytest using selenium and selenoid.
I have a class that inherits from BaseCase and for example when I want to open a webpage I write super().open(URL). Or, if I want to click on an element I write: self.click(element_selector).
I am a bit confused, however, on why most other examples I find online first have to create a webdriver, and only then can they do actions such as open and click, thru it. Whereas I can just access it thru class object (self.click()).
I understand that this has to do with my using selenoid. However, I am not quite sure how it all fits together. I have had a lot of trouble finding an explanation online, as every time I try to type in the words selenoid and webdriver together, google assumes I mean selenium. I can't find any related results. Anyone have an explanation on this? (Or, even a better search term to use than Selenoid Webdriver Pytest or What do I use instead of Webdriver in Selenoid?
I suggest implementing your tests in the way like tutorials suggest, at least until you'll feel experienced. In this way, you will do your tasks in the way most other people do.
So I suggest do not use some libraries classes inheritance, but creating webdriver instance and using it. (But still, it's your choice and up to you). I cannot add anything more without seeing your code..
Selenium + Selenoid
Selenoid behaves like Selenium Grid.
If your Selenoid started on localhost:4444, just
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
driver = webdriver.Remote(
command_executor='http://localhost:4444/wd/hub',
options=chrome_options
)
driver.get("http://www.google.com")
driver.quit()
Setup Selenoid
(assumed you already have Docker):
1 Download cm from
https://github.com/aerokube/cm/releases
2 Run chmod +x cm
3 Run
./cm selenoid start
And your Selenoid will be ready to accept requests.
Check http://localhost:4444/status.
References
https://aerokube.com/selenoid/latest/
https://www.selenium.dev/documentation/webdriver/remote_webdriver/
Case Step:
Open an web browser to do some step
Open Android device with Appium to do some step.
Note: Those two steps should be run in one test of TestNG XML.
If you don't want both driver session be active but want to switch to another driver by kill current driver session you can set driver.name property in code and it will do the needful. Changing any of following property in code teardowns existing driver and creates new driver instance:
driver.name
driver.additional.capabilities
remote.server
remote.port
For example:
getBundle().setProperty("driver.name","chromeDriver");
//do the needful
getBundle().setProperty("driver.name","anotherDriver");
//it will teardown chromedriver and create anotherDriver session in next driver call.
//do the needful
If you want to have both driver session to be active, Support for Multiple driver in the same thread/test-case has been added since 2.1.11. To change driver within test case you can use setDriver(String driverName) method of QAFTestBase. For instance:
TestBaseProvider.instance().get().setDriver("chromeDriver");`
Refer details in commit notes.
I use selenium grid to run my tests on several machines. I want to run tests on different browsers, but I have no idea how to set several browser names in desired capabilities. Here is my code:
DesiredCapabilities caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true);
caps.setPlatform(Platform.WINDOWS);
caps.setBrowserName("firefox"); //how can I also add a chrome?
You can add only 1 browser capability at a time. If you want to add more browsers to run, you should you threading to create multiple runs of the same script.
So the shortest answer to your question is that you can't specify multiple browsers in a single capability.
Here is logic that might help. Note this is just a pseudo code.
Array list = array(firefox,chrome,IE)
for each item in list
DesiredCapabilities caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true);
caps.setPlatform(Platform.WINDOWS);
caps.setBrowserName(item);
driver related code
end for
I am migrating from RC to webdriver.
In my existing project I use methods from the Selenium Class like
selenium.click()
selenium.type()
etc.
Do I need to change these to the equivalent webdriver commands, or is there a way i can still use these commands?
I use firefox 12, Eclipse IDE
There is the WebDriverBackedSelenium. Essentially this is a bridge between the RC API and WebDriver API. This will do what you are after, there will be some modification to code, but majority will still be the same. It gives you the flexibility of the WebDriver itself, while keeping old code the same.
It is highly recommended to fully convert your solution to use the WebDriver API directly.
The WebDriver API is constantly being updated, worked on and supported.
The RC API and the "RC-WebDriver-Bridge" (WebDriverBackedSelenium) won't be.
Page on WebDriverBackedSelenium exists here:
http://seleniumhq.org/docs/03_webdriver.html#alternative-back-ends-mixing-webdriver-and-rc-technologies
Sample usage to create a new instance of Firefox:
var driver = new FirefoxDriver();
var selenium = new WebDriverBackedSelenium(driver, baseUrl);
selenium.open("http://www.google.com");
selenium.type("name=q", "cheese");
selenium.click("name=btnG");
selenium.stop();
After creating a WebDriverBackedSelenium instance with a given Driver, one does not have to call start() - as the creation of the Driver already started the session. At the end of the test, stop() should be called instead of the Driver's quit() method.
This is more similar to WebDriver's behaviour - as creating a Driver instance starts a session, yet it has to be terminated explicitly with a call to quit().
in a continuous integration build environment when running several Selenium tests in parallel (using Firefox driver) for different applications and each tests records its screenshots after every "action" (e.g. navigating to a page, submitting a form etc.) it seems like that whichever application window pops up that one gets on the top of the z-axis and will have the focus.
So using the method getScreenshotAs() from the Selenium API to record images results in mixed up screenshots sometimes showing one application and sometimes the other application.
Recording the HTML responses with getPageSource() on the other hand seems to work correctly using the Firefox driver instance "bound" to the test.
Is there any solution how to deal with the mixed up image screenshots? Is there a possibility how to ensure that getScreenshotAs() only consideres its own Firefox driver instance? Thanks for any hints!
Peter
I don't know what flavor of selenium you are using but here is a reference to the API that looks like it would fix your problem, but I have never tested it.
http://selenium.googlecode.com/svn/trunk/docs/api/dotnet/index.html
What that link shows is the IWrapDriver which according to the documentation Gets the IWebDriver used to find this element.
So from my understanding you could set your IWebDriver in your method and then wrapit with the IWrapDriver and then use that to reference for you getScreenShotAs();