QAF - wanted to open and close the browser with each test - selenium

I am using QAF open source Java library in my UI Automation Framework and wanted to open and close the browser with each test. But, can't do it with below code hence browser which is opened by testSuccessfulLogin() keeps opened hence the testFailedLogin() fails.
public class LoginTestCase extends WebDriverTestCase {
#Test(testName="SuccessfulLogin", description="Successful Login with valid username and password", groups={"SMOKE"})
public void testSuccessfulLogin() {
LoginPage loginPage = new LoginPage();
loginPage.openPage();
verifyLinkWithTextPresent("Or Sign Up");
loginPage.enterUsername("asdf.asdf");
loginPage.enterPassword("Asdf#1234");
loginPage.clickLogInButton();
verifyLinkWithTextPresent("Dashboard");
verifyLinkWithTextPresent("Logout");
}
#Test(testName="FailedLogin", description="Login with blank username and password", groups={"SMOKE"})
public void testFailedLogin() {
LoginPage loginPage = new LoginPage();
loginPage.openPage();
verifyLinkWithTextPresent("Or Sign Up");
loginPage.enterUsername("");
loginPage.enterPassword("");
loginPage.submitLoginForm();
verifyLinkWithTextPresent("Dashboard");
verifyLinkWithTextPresent("Logout");
}
}

You can achieve it by setting selenium.singletone=method. Specify it in application properties or in xml configuration file. Refer list of properties and how to set properties.

Related

Xero API Allows connection but fails to redirect back, has an uncaughtreferenceerror: fbq is not defined

Upon running the program I am redirected to sign in with xero. Once I sign in I am able to choose an organization to allow access to the app
Upon clicking allow access I get redirected to the default "This site can't be reached" error page.
If I look at the console output when I click the button, for a few seconds an "uncaught reference error: fbq is not defined" is shown. Unfortunately it goes away before I can click on it.
Here is some of the relevant code:
void LoginToXero()
{
var xeroLoginUri = XeroService.GetLoginUri();
OpenBrowser(xeroLoginUri);
var listener = new HttpListener();
listener.Prefixes.Add(XeroService.CallbackUri);
listener.Start();
Console.WriteLine("Waiting for the browser to callback from Xero login page...");//Logs
var context = listener.GetContext();//Does not progress past here
//...
}
public static class XeroService
{
public static string CallbackUri => "xxxxxxxxxxxxx";
static string xeroState = Guid.NewGuid().ToString();
static string oAuth2Token = "";
static XeroClient xeroClient = new XeroClient(new XeroConfiguration
{
ClientId = "XXXXXXXXXXXXXX",
ClientSecret = "XXXXXXXXXXXXXXXXXXXX",
Scope = "openid payroll.employees",
CallbackUri = new Uri(CallbackUri)
});
public static string GetLoginUri()
{
xeroClient.xeroConfiguration.State = xeroState;
return xeroClient.BuildLoginUri();
}
}
Please note all sensitive data has been replaced by "XXXXXXXXX"
I have tested both localhost callback URI's (with specified ports) and custom ones that redirect to localhost via the host file on my machine
I have also tried running it on Windows 11 and Windows 10, both with the firewall enabled and then with it disabled
Any help would be greatly appreciated
The problem was that the listener and the App was set up for https, changing it to http and making sure there was an explicit port resolved the issue

How to generate Allure report using cucumber and JUnit?

I am trying to create allure report using cucumber + Junit but allure-result folder is not getting created. Though test cases are getting passed successfully just I want to create allure-result folder which is not getting created. Requesting you suggestions.This is my project Structure
Step Defination File:
public class CustomerInfoVerification {
#Given("^user is already on home Page$")
public void user_is_already_on_home_Page() throws Throwable {
System.out.print(" thid is Given");
}
#When("^click on Pattinson, Robert provider$")
public void click_on_Pattinson_Robert_provider() throws Throwable {
System.out.print(" thid is When");
}
#Then("^user verifies unm and password$")
public void userVerifiesGeography() throws Throwable {
System.out.print(" thid is Then");
}
}
Feature File:
Feature: Rule management module
Scenario: Provider information module
Given user is already on home Page
When click on Pattinson, Robert provider
Then user verifies unm and password
Image for [POM.xml][2] POM.xml
POM.xml filenter code herees image is attached

Spring boot ldap security

Hello I have a problem creating simple login with Ldap. I have downloaded getting started project from spring.io website: Getting started LDAP.
It is working perfectly with ldif file but I want to replace it with running ldap server. I have tried it for days with no progress. I get best results with this piece of code (replaced in WebSecurityConfig of getting started project)
#Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
#Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().authenticated().and().httpBasic();
}
#Override
protected void configure(AuthenticationManagerBuilder authManagerBuilder) throws Exception {
authManagerBuilder.authenticationProvider(activeDirectoryLdapAuthenticationProvider()).userDetailsService(userDetailsService());
}
#Bean
public AuthenticationManager authenticationManager() {
return new ProviderManager(Arrays.asList(activeDirectoryLdapAuthenticationProvider()));
}
#Bean
public AuthenticationProvider activeDirectoryLdapAuthenticationProvider() {
ActiveDirectoryLdapAuthenticationProvider provider = new ActiveDirectoryLdapAuthenticationProvider(null, "ldap://ip:port/", "ou=GROUP,dc=domain,dc=com");
provider.setConvertSubErrorCodesToExceptions(true);
provider.setUseAuthenticationRequestCredentials(true);
return provider;
}
}
If i try to login with good username and password in format "username" "password" console output: ActiveDirectoryLdapAuthenticationProvider : Active Directory authentication failed: Supplied password was invalid
If I use "username#domain.com" and good password, page just reloads with no output to console.
If I use random username and password console: Active Directory authentication failed: Supplied password was invalid
Can someone help?
As suggested in comment I have turned on logging and found out that the problem is same with "username#domain.com" too.
Problem was in aciveDirectoryLdapAuthenticationProvider() there were 3 problems in it.
I have removed OU group from rootDn and added domain so we can use only username to log in.
ActiveDirectoryLdapAuthenticationProvider provider = new ActiveDirectoryLdapAuthenticationProvider("domain.com", "ldap://ip:port/", "dc=domain,dc=com");
changed searchfilter of provider
provider.setSearchFilter("(&(objectClass=user)(sAMAccountName={0}))");
and finally I had to change ActiveDirectoryLdapAuthProvider searchForUser method because it was matching "username#domain.com" with sAMAccountName istead of "username". This:
return SpringSecurityLdapTemplate.searchForSingleEntryInternal(context,
searchControls, searchRoot, searchFilter,
new Object[] { bindPrincipal });
replaced with this:
return SpringSecurityLdapTemplate.searchForSingleEntryInternal(context,
searchControls, searchRoot, searchFilter,
new Object[] { username });
Complete aciveDirectoryLdapAuthenticationProvider:
#Bean
public AuthenticationProvider activeDirectoryLdapAuthenticationProvider() {
ActiveDirectoryLdapAuthenticationProvider provider = new ActiveDirectoryLdapAuthenticationProvider("domain.com", "ldap://ip:port/", "dc=domain,dc=com");
provider.setSearchFilter("(&(objectClass=user)(sAMAccountName={0}))");
provider.setConvertSubErrorCodesToExceptions(true);
provider.setUseAuthenticationRequestCredentials(true);
return provider;
}
Can someone provide better solution for the second/third problem? maybe better searchfilter? I dont have any field in ldap that matches "username#domain.com" format of bindPrincipal that is using ActiveDirectoryLdapAuthProvider.

Selenium 2 browser instances for a single test

I am using phpunit as a wrapper for selenium. I have a test that simulates two users on the same website. So I need to have two browsers open that can't share cookies - it can't just be two windows. They are the same test, so for example a user would click something in the first browser instance and the other user would look for a change in the other browser instance. Logging out and back in as the other user is not an option.
Is there a way to do this?
Disclaimer: I haven't tried this at all, but the pattern might work.
Unfortunately the PHPUnit WebDriver implementation is tightly coupled to the unit test framework code. However, you could try something like this in order to have 2 different web driver instances running in parallel:
<?php
class WebTest extends PHPUnit_Extensions_Selenium2TestCase
{
private $driver1;
private $driver2;
protected function setUp()
{
$this->driver1 = $this->createDriver();
$this->driver2 = $this->createDriver();
}
protected function createDriver()
{
$driver = new PHPUnit_Extensions_Selenium2TestCase();
$driver->setBrowser('firefox');
$driver->setBrowserUrl('http://www.example.com/');
$driver->start();
return $driver;
}
public function testTitle()
{
$this->driver1->url('http://www.example.com/');
$this->driver1->assertEquals('Example WWW Page', $this->title());
$this->driver2->url('http://www.example.com/');
$this->driver2->assertEquals('Example WWW Page', $this->title());
}
protected function tearDown() {
$this->driver1->stop();
$this->driver2->stop();
}
}
?>
Theres quite a lot that could potentially go wrong with this but you could try it.
Alternatively you could ditch the PHPUnit integration for this particular test/tests and use a dedicate PHP WebDriver API like PHP-SeleniumClient, which would give you better control over the WebDriver instances.

Work with OData secured service

I want to generate entity classes and Service class of OData secured service.
In OData Java extension page it is written that I need to use org.restlet.ext.odata.Generator class that should get uri and output directory parameters.
But if my OData service is secured the generator instance is not able to generate service classes without username and password of the service.
I did not find any way to pass username and password to generator class.
I get 401 HTTP response code.
Please help.
In the org.restlet.ext.odata.Generator class, in the method main,
The following code would clear the credential details set in the setCredentials() method.
Service service = new Service(dataServiceUri);
if(service.getMetadata() == null)
{
errorMessage = "Cannot retrieve the metadata.";
}
Kindly provide a solution for this issue as I am currently unable to generate the classes for my rest service as the service is secured with an user password.
I tried the following code to generate the code for my secured service uri:
import org.restlet.ext.odata.Generator;
import org.restlet.ext.odata.Service;
import org.restlet.data.ChallengeResponse;
import org.restlet.data.ChallengeScheme;
public class ODataRestletGenerator extends Service {
public ODataRestletGenerator(String serviceUri) {
super(serviceUri);
}
public static final String APPLICATION_URI = "http://ldcigkd.xxx.yyy.corp:50033/xxx/opu/sdata/IWCNT/CUSTOMER/";
public static void main(String[] args) {
// Add the client authentication to the call
ChallengeScheme scheme = ChallengeScheme.HTTP_BASIC;
ChallengeResponse credentials = new ChallengeResponse(scheme, "user", "pwd");
new ODataRestletGenerator(APPLICATION_URI).setauth(credentials);
String[] arguments = { APPLICATION_URI, "/customer/src" };
Generator.main(arguments);
}
private void setauth(ChallengeResponse credentials) {
super.setCredentials(credentials);
}
}
In the org.restlet.ext.odata.Service subclass that is generated by OData extension, you can call setCredentials() and pass an instance of ChallengeResponse including scheme (BASIC?), login (identifier) and password (secret).