Calling authentification feature from another feature - selenium-webdriver

I'm starting learning automation test using selenuim webdriver & cucumber, I have tow features:
Authentification.feature
Feature: Authetification
#Test1
Scenario: Authetification (credential)
Given Open the Url
When Enter the Username and Password
Then Click connect_btn
CreateUser.feature
Feature: Create User
#Test2
Scenario: Create User
Given Open users list
When Fill the form
Then Click save_btn
How to call the authentification into CreateUser.feature ?
Thanks & Regards,Patricia

Cucumber does not support calling one feature from another feature (or one step from another step).
From the Cucumber docs - FAQ:
"How do I call other steps or scenarios?
Each scenario should be independent; you should be able to run them in any order or in parallel without one scenario interfering with another.
Each scenario should test exactly one thing so that when it fails, it fails for a clear reason. This means you wouldn’t reuse one scenario inside another scenario.
If your scenarios use the same or similar steps, or perform similar actions on your system, you can extract helper methods to do those things."
In your case, I'd recommend thinking about how to get your system to a state where a user is logged in at the start of any test where that is a precondition, without actually testing the login feature each time. That way if the login functionality breaks for any reason, you can still test other functionality of your application.

Related

Capybara Selenium reuse existing browser session, instead of opening new windows?

In Capybara, How can I reuse existing browser to continue run step next. Instead of star a new session and open a new windown and next run a ton of step before.
For example :
First:
session = Capybara::Session.new(:headless_chrome, Capybara.app)
session.open(url)
session.click(...)
sesion.quit()
Second Time:
session = ...#retry the first session state
sesion.do_something()
Capybara is designed as a testing tool, where you want every test to be completely independent of other tests. Because of that it has no support for storing/reloading a session, and uses a fresh browser instance (data-dir, etc) for each session. To prevent creation of a completely new browser setup every time you create a new session you could pass your own --user-data-dir=<some_directory> option when registering your Capybara driver, but it's not Capybara supported usage (and would really not be a good idea if you're actually doing testing rather than web scraping). Another option if all you really want is the cookies retained would be something like https://github.com/kyamaguchi/capybara-sessionkeeper (again bad idea if you're testing since it couples tests to each other).

Synchronous Call outs from Standard Pagelayout In Salesforce

There is a requirement to make synchronous call out from standard page lay outs of salesfore say for eg. standard case layout. As of my knowledge we can not make a synchronous call out in context to a standard page layout. As process builder or workflow or js button everything will work in an asynchronous context. Want to confirm that , please help with your views.
Erm... no?
Process Builder, Workflow Rule, Trigger - they all fire on event (insert, update). They're all synchronous (the whole operation waits for them to finish saving). Just viewing a record doesn't count as an event. I think you're confusing the "what triggers the action" and "what kind of action happens". Try to distinguish the two. It's like workflows - a workflow rule (condition to be met) is one thing and then what happens (field update, new task, email, outbound message) is completely different thing.
From "clicks not code" functionality Outbound Messages and emails are asynchronous - but as I said above - just viewing a record doesn't count as update, nothing will fire. Callouts done from apex (and you have several options discussed below) can be either synchronous or async. So it's whatever you want really.
You might look into:
a Visualforce page which you'll embed on the page layout (either directly or as a Chatter action for example). That page's apex controller could do the callout.
Or maybe you'd be able to do it in VF from JavaScript (without apex) - make a REST call to your url, process results... There are tons of code samples how to integrate Google Maps for example, this wouldn't be too different.
or (bit of future thinking) make a Lightning Component. You'll be able to embed it in the Lightning App Builder (the "better" page layouts) directly. in Classic SF you'd have to make it a Chatter Action or use "Lightning Out" to reuse a component in a VF page and embed that instead.
Bit more advanced (and paid extra) would be to use Salesforce Connect a.k.a Lightning Connect. Try to pass the Trailhead, easier than explaining it here. You could end up with related list of external records under the case and user wouldn't even realise this data is not hosted in SF. Connect requires OData compatible data source or a piece of Apex that acts as adapter and pretends to return valid format.
If it's about Cases - maybe you can do something fancy using the Service Cloud Console. You'd have to experiment a bit but maybe one of side panels could be a VF page or <iframe> to another system. Maybe you could make something happen with Macros...

How to make ID's generic for different website

I am automating tests using selenium webdriver using test ng framework. Here am trying to implement POI and factory Design pattern.
Basically am testing on two websites (Which differs in GUI interface)which has login pages
Login Name and Password and login button but the challenging part is webelements has different ID in both the websites.
HOw to write a generic methods for this?
For locators i have a an enum class where i take the instance of each value and call it in the method.
As id is different than for sure you need to define both elements. There is no such solution for it.
In your testcase you can implement a check which defines that you on which environment and accordingly it will pass the element

Is there a way a method can be triggered or run during a salesforce package installation process?

I would want to do this to run post installation setup process like adding custom data that is required for the application to run.
One option I am aware of is to Write Installation and Setup instructions for users. Create visualforce page and include a button on this page. Redirect user to this page as the process of Installation and ask the user to click the button.
I only wanted to know If there was a more elegant way to solve the problem and if there is a way to call a method during the installation process.
Salesforce has recently implemented the ability to execute scripts (as Apex) during package Install / Uninstall:
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_install_handler.htm
No, we can't have a post installation script for the app. What you are saying is best solution, just keep a custom setting to flag, if initial setup is not done, then redirect to the setup page first, other wise do the normal work.
My question would be revolving around why you need custom data for the app to run? One of the things Salesforce look for when doing a security review of your code and the unit tests you have is to check to see if you are requiring data in your org as this is bad practice. Note that if your app is requiring specific data to run then it cannot be tested properly as the data will not be in the org when running the tests on install.
What is the data you are requiring? Could it be stored in an xml like static resource file or something similar for you to load and parse as it is needed?
Paul

Making a drupal database call using ajax

I want a link that when you click on it, it will call a simple ajax query which updates a database entry. Normally this would be easy, but because authentication needs to happen before the query is executed, I need to be able to execute the Ajax Query AS THE CURRENTLY LOGGED IN USER. I.e. I need access to the $user variable and I don't want to create a new connection.
Does Drupal have native functions that can do this? Is there something I can use to do this?
You're going to want to create a module to handle this. Then, whatever function you call through the callback will have complete awareness of the logged in user.
Keep in mind that if someone makes a link that goes to your AJAX destination on their website, and can trick people into clicking it (or, for that matter, makes that link the src on an img tag), then weird things can happen to people's data without them meaning to.
I suggest the use of a token and checking that the token submitted as part of the link matches something to do with the user. Check drupal_get_token() for a good way to generate one.
Either create a menu item in a module implementing hook_menu() and specify a callback to a function handling this request - or use the Services module and create a new service module.

Resources