Selenium and Appium automation through Serenity - selenium

My usecase involves both Web and mobile devices automation in sequence. The automation flow has certain actions and verifications to be done on Web and later the actions and verifications are to be done on Mobile.
The desired capabilities allow us to select either Chrome or Appium. Is there an example where I can start both Chrome browser and emulator together and run the tests through Serenity and Cucumber?

Related

QAF - How to automate both WEB and MOBILE app using QAF

I am new to QAF. I need to automate both web and mobile app together. Let say, I have to do fund transfer using mobile native app and logout then immediately open desktop browser(Not Mobile browser) and open web application to verify the same transaction.
Since we need to configure both Appium driver and browser driver to achieve this scenario. How to handle this scenario using QAF framework.
With QAF you can interact with multiple device/driver in single testcase. QAF has support for Multiple Devices in one testcase. Driver can be for mobile or desktop browser. Provided capabilities for different drivers you can switch between drivers as required in test case. Assumed that you have provided capabilities for chrome and android driver you can use more than one driver in same test as below:
QAFTestBase testbase = TestBaseProvider.instance().get();
testbase.setDriver("androidDriver");
//some steps with mobile
testbase.setDriver("chromeDriver");`
//some steps with chrome browser instance 1
testbase.setDriver("chrome2Driver");
//some steps with another chrome browser/driver`
testbase.setDriver("androidDriver");`
//switch to do something with mobile driver
testbase.setDriver("chromeDriver");`
//switch to do something with chrome browser instance 1
//tear down test case specific driver session that are no-more required
testbase.tearDown("chromeDriver");
testbase.tearDown("chrome2Driver");
testbase.setDriver("androidDriver");`
//switch back to mobile driver

What Is Selenium And What Is WebDriver?

What is Selenium?
When you open the official page of the Selenium, the first thing you read is "Selenium automates browser" in "What is Selenium?" section.
The section "Which part of Selenium is appropriate for me?" below offers the choice between Selenium WebDriver and Selenium IDE.
From this, I deduce that Selenium is a collection of tools and the collection comprises IDE, WebDriver API(language binding), Grid, Selenium Standalone Server, browser driver. One has to download the appropriate ones to build a project.
What is WebDriver?
WebDriver is an API. It is written in more than one language which and they are called language bindings. The API has functions to control a browser. You use the functions in writing a script that controls a browser in the way(test case) you want.
This is what I know. Please correct me wherever I'm wrong. I want to know the answers to the two questions in the interview point of view.
Selenium
Selenium is a free (open source) automated testing suite for web applications across different browsers and platforms. Primarily it is used for automating web applications for testing purposes, but is certainly not limited to just that. Selenium has the support of all of the major browser vendors who have taken (or are taking) steps to make Selenium a native part of their browser. It is also the core technology in countless other browser automation tools, APIs and frameworks.
Selenium is not just a single tool but a set of different software tools each with a different approach to support the test automation of an organization. From a broader perspective previously it had four components as follows:
Selenium Integrated Development Environment (IDE)
Selenium Remote Control (RC)
WebDriver
Selenium Grid
An year ago, Selenium RC and WebDriver are merged into a single framework to form Selenium 2.x. Perhaps, Selenium 1 refers to Selenium RC. The current released version is Selenium 3.x.
WebDriver
Selenium-RC worked the same way for each supported browser. It injected javascript functions into the browser when the browser was loaded and then used its javascript to drive the AUT within the browser. Selenium WebDriver fits in the same role as Selenium-RC did and has incorporated the original 1.x bindings and included the WebDriver API. It refers to both the language bindings and the implementations of the individual browser controlling code. This is commonly referred to as just WebDriver. In short, WebDriver is the remote control interface that enables introspection and control of user agents. WebDriver provides a platform and language-neutral wire protocol as a way for out-of-process programs to remotely instruct the behavior of web browsers.
Highlights of WebDriver
WebDriver is designed in a simpler and more concise programming interface along with addressing some limitations in the Selenium-RC API.
WebDriver is a compact Object Oriented API when compared to Selenium1.0
It drives the browser much more effectively and overcomes the limitations of Selenium 1.x which affected our functional test coverage, like the file upload or download, pop-ups and dialogs barrier
WebDriver overcomes the limitation of Selenium RC's Single Host origin policy.
Current Implementation
WebDriver is the name of the key interface against which tests should be written in Java/C#/Ruby/Python/NodeJS, the implementing classes which you can use are listed as below:
ChromeDriver
EventFiringWebDriver
FirefoxDriver
HtmlUnitDriver
InternetExplorerDriver
PhantomJSDriver
RemoteWebDriver
SafariDriver
What is Selenium
It is a suite of tools that can be used to automate web browsers testing.
Each tool serves different purpose.
List of tools:
Selenium IDE
Selenium RC
WebDriver
Selenium Grid
Selenium RC was merged with WebDriver since Selenium 2
What is WebDriver
Selenium WebDriver is an interface that permits us to execute tests over browsers.
Selenium WebDriver allows us to choose a programming language of your choice to create test scripts.
Please find the image below explaining how exactly WebDriver communicates with the browser :
What is Selenium?
Selenium is a framework where scripts are written to run and execute webDriver which in turn controls browser.
What is WebDriver?
WebDriver is an API, the name itself suggests driving the web browser or controlling the web browser by using libraries and commands.
The one and only job of WebDriver is to control the browser, it doesn't know anything about testing and how to interact with browser, At this point FrameWork comes into picture where Scripts are written to run and execute WebDriver.
What is Selenium?
You can say it is a web application automation framework.
What is WebDriver?
This is certainly an API but to understand easily you can think it as a library collection.
I think it's also worth noting that the WebDriver controls the browser, and that Selenium is the piece that sends/receives method calls and data from/to the driver using the "wire protocol" that the WebDriver creates. So the WebDriver is the bridge from the browser to any other code that wants to communicate with it. Selenium also provides an interface (in the coding sense...) that is standard across different WebDrivers. So when you declare a WebDriver type it is implementing the interface. (This is my current understanding anyway and I'm always learning something new!)

How to test my selenium web test cases on mweb

I have few selenium test cases; running fine on desktop website. My website is responsive; hence works fine on Mobile Browser also. How do I test my test cases on Mobile Browser ?
If your requirement is to test your site in Mobile view (As your site is responsive) then following code may help you -
FirefoxProfile ffprofile = new FirefoxProfile();
ffprofile.setPreference("general.useragent.override", "iPhone"); //this will change the user agent which will open mobile browser
WebDriver driver = new FirefoxDriver(ffprofile);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().window().setSize(new Dimension(360,640)); //just to change the window size so that it will look like mobile
driver.get(siteURL);
You can use Appium to support the
Mobile web apps are web apps accessed using a mobile browser (Appium supports Safari on iOS and Chrome or the built-in ‘Browser’ app on Android).
Its design is based on the WebDriver API, so you’re free to use whatever test runner and test framework you already have. Keeping this in mind, your current Test engine should be insensitive to the application drivers and those are just plug&play “automation libraries” anyway.
Here is the Appium GitHub examples repo, which I like to use. You can find examples in:
RobotFramework
dotnet
java
node
perl
php
python
ruby

Record browser sessions via selenium-webdriver

Is there a way to record / generate a video file of the browser session for selenium webdriver with the following setup?
Environment / Test Setup:
e2e web tests (written in any language)
selenium standalone server with chrome
Since, there is no direct support from selenium, you may use third party tool like Monte Media Library. See the link:
How to perform screen recording with the help of selenium?
Hope, this will help you.

What does mean by "running selenium tests are in headless mode " in jenkins

Can anyone explain what is running selenium tests in headless mode in jenkins?
As per comment it's a way of running tests in a browser that doesn't have a GUI attached to it
What is a headless browser? (Quoted from ToolsQA)
Headless browser is a term used to define browser simulation programs
which do not have a GUI. These programs behave just like a browser but
don’t show any GUI. Famous ones are HtmlUnit and the NodeJs headless
browsers. There are a good number of more browsers too.
What is the use of Headless browsers?
Headless browsers are typically used in following situations
You have a central build tool which does not have any browser installed on it. So to do the basic level of sanity tests after every
build you may use the headless browser to run your tests.
You want to write a crawler program that goes through different pages and collects data, headless browser will be your choice. Because
you really don’t care about opening a browser. All you need is to
access the webpages.
You would like to simulate multiple browser versions on the same machine. In that case you would want to use a headless browser,
because most of them support simulation of different versions of
browsers. We will come to this point soon.
Things to pay attention to before using headless browser
Headless browsers are simulation programs, they are not your real
browsers. Most of these headless browsers have evolved enough to
simulate, to a pretty close approximation, like a real browser. Still
you would not want to run all your tests in a headless browser.
JavaScript is one area where you would want to be really careful
before using a Headless browser. JavaScript are implemented
differently by different browsers. Although JavaScript is a standard
but each browser has its own little differences in the way that they
have implemented JavaScript. This is also true in case of headless
browsers also. For example HtmlUnit headless browser uses the Rihno
JavaScript engine which not being used by any other browser.