How to make ID's generic for different website - selenium-webdriver

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

Related

Calling authentification feature from another feature

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.

How to add captcha in React JS besides google recaptcha v2

I am using reactjs & mvc web api 2 to build my website. and I want to add captcha in my UI form.
Is there any other way to add captcha in reactJS / Web Api 2 beside using google recaptcha.
It seems everybody are using recaptcha v2. but in my case, I prefer use text based captcha, like recaptcha v1.
Thanks
You don't have to rely on the Google's solution to this problem. If you're using React you can simply create your own component named Captcha which will decide if the form can be passed. How to do that?
Create new React Component Captcha and place it wherever you want
in your app. You can generate 2 random Integers and ask the user to
add them.
According to the above create a verification method. Just check if the result given is equal to what it should be. Place the verification on the server side of your application, since browser side can be manipulated.
Only pass the form when the verification has passed.
Set some delay if your user fails the
verification. Can be small- remember it is to prevent bots from
spaming you.
As simple as that! Your imagination is the limit. Inside of that React Component you can define whatever method of verification you'd like to. Can be simple math task, can be distinguishing the shapes, colors, whatever you want...

Controller logic in Element View in CakePHP

I'm working on a really big project. The aspect I'm currently working on requires that email templates are sent to a user when they're added to a learning course by another user.
The controller that deals with the request, does a bunch of str_replace tasks to find variables in the text (which the user can edit before adding another user to the learning course) and then replaces it with some values in the DB.
I took over this project and I'm not happy with the way half the things are done but time costs dictate I rather just go along with it.
The email is sent using Cake's native email function. It uses a template to capture data and send to the user.
Here's the question:
Should I keep the logic in the controller or do you think it's safe to move it to the element view's .ctp file?
My first instinct is to leave it in the controller as per the usual MVC separation ideals.
Cheers
This is a very important question - what are you using exactly for the email? The old email component or the new CakeEmail class? Which CakePHP core version are you using?
Here are some plausible aproaches here. You can:
Set all those variables, pass them to the view and do all the "replacing" there.
Encapsulate this logic in a component, attach it to your controller(s) and use it.
Just leave it in a private function within the controller and call that function whenever needed. (not really MVC)

DotNetNuke -- Inserting URL parameters in forms

We are migrating our website to DotNetNuke and are looking to replicate the functionality of our survey page. Currently, on the bottom of every e-mail we send through our CRM system, there is a link to a satisfaction survey along with some parameters to pre-populate some of the fields. So the URL looks something like like:
/survey.aspx?ticketID=1234&userName=John+Doe
I found the custom module "helferlein_Form" which seems okay for actually creating the form that the user fills in, but I don't see a way to pre-populate the fields. DotNetNuke does let you insert tokens(ex: [Date:now], [User:username]), but I don't see a way to grab individual parameters from the URL. Is there something I'm missing that will let me do that?
I'm not familiar with that module either, but I would strongly recommend using Xmod for customized forms that allow you to easily grab url parameters.
I'm not sure about the module you reference.
However, in my experience Dynamic Forms from Data Springs would fit the bill perfect. It has the ability to pre-fill and even run custom SQL queries to get data.
You should definitely try our My Tokens module.
It allows you to access the URL parameters using [Get:ticketID] or [QueryString:tickedID]. You can also build SQL tokens that use these parameters to return a list of items for example to populate a dropdown.
Also try our Action Form module which integrates very nice with My Tokens.
If you have a module you like and want to use you can always write a little javascript to grab the variables out of the URL and pre-populate your form fields using javascript.

CakePHP 2 - single core, two apps, one inside the other?

I'm fairly new to CakePHP and am trying to setup a custom admin area for my app. I realize Cake can create an admin area with scaffolding but I'd like to build something much more customized, and have it accessible from via /admin/, with one app for the public side and another for the admin.
Ideally, the structure would be:
www
^- apples (public application here)
^- apples-admin (password-protected control panel)
I'm having a hard time figuring out how to set this up using a single Cake core and two apps - one for "apples" and one for "apples-admin". I've read some notes about modding PHP's include path, but that won't be possible in the production environment. The other notes I see about changing CAKE_CORE_INCLUDE_PATH aren't very clear on where I would make that change, and it doesn't appear as though that would get me the app-inside-app structure I'm after.
Is what I'm trying to do possible? Am I better off using just a single app for both the public side and admin area?
You can achieve what you want using a single application.
To get up and running:
Use Prefix Routing to map your admin actions.
Then use the Auth component to restrict access to your 'admin' actions. I recommend setting up a User model to manage your users and using the FormAuthentication handler for logging in.
If you haven't used Bake for code generation before, then that's also worth looking into. It'll help create a base starting point for a lot of your admin functions.
Good luck.

Resources