Selenium webdriver script not able to log in into magento Panel - magento

I am trying to log in to Magento Admin panel via Selenium web Driver script but its not working .
It identifies login button and clicks on login button but it is not getting in to next page once log in successful.
userid : magadmin
Password : Lean5226
when you try it with iDE it is working
Website :
54.201.104.110/magento/env-ee/index.php/admin
Here is below script :
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "D:/ChromeDriver/chromedriver.exe");
WebDriver driver=new ChromeDriver();
System.out.println("Fire fox started");
String baseUrl = "http://54.201.104.110/";
driver.get(baseUrl + "/magento/env-ee/index.php/admin/");
driver.findElement(By.id("username")).clear();
driver.findElement(By.id("username")).sendKeys("magadmin");
driver.findElement(By.id("login")).clear();
driver.findElement(By.id("login")).sendKeys("Lean5226");
Thread.sleep(3000);
String att=driver.findElement(By.cssSelector("input.form-button")).getAttribute("value");
System.out.println(att);
WebDriverWait wait = new WebDriverWait(driver, 15);
driver.findElement(By.cssSelector("input.form-button")).click();
System.out.println("Waiting");
Thread.sleep(3000);
driver.close();

This post is a little old, but in the event that other people find it interesting you can do this using Magium with a fairly simple command. The following code is from one of the blog posts on logging in to the Magento admin IU
class LoginTest extends \Magium\Magento\AbstractMagentoTestCase
{
public function testLogin()
{
$this->getAction(\Magium\Magento\Actions\Admin\Login\Login::ACTION)->login();
}
}
There is some additional information on how to configure it on the blog post.

Related

Has anyone successfully implemented Azure Active Directory B2C for auth using Microsoft.Identity.Client 1.1.0-preview?

I have been struggling with this for several days (three actually). I have AAD B2C working on a web app and an api. I cannot get it running on my Xamarin mobile project. I am using the UWP project to test my configuration since it has the easiest app to troubleshoot on a Windows 10 machine. I am using Visual Studio 2015 Pro.
I am using the Microsoft.Identity.Client 1.1.0-preview.
I used this as my starting point for my attempt to implement.
https://github.com/Azure-Samples/active-directory-b2c-xamarin-native
Right now the project will compile and launch. When I click on Sign in, I get a WebView, but it doesn't look exactly right....
[First Image in Screenshots]
Here are my variables...
public class Constants
{
public static string ApplicationID = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
public static string[] Scopes = {""};
public static string SignUpSignInPolicy = "B2C_1_Standard_SignUpSignIn";
public static string ResetPasswordPolicy = "B2C_1_Standard_PasswordReset";
public static string EditProfilePolicy = "B2C_1_Standard_EditProfile";
public static string Authority = "https://login.microsoftonline.com/[MyTennantName].onmicrosoft.com/B2C_1_Standard_SignUpSignIn";
public static string AuthorityEditProfile = "https://login.microsoftonline.com/[MyTennantName].onmicrosoft.com/B2C_1_Standard_EditProfile";
public static string ApiEndpoint = "https://[MyTennantName].onmicrosoft.com/apiservices";
public static UIParent UiParent = null;
}
My Login method is....
async void OnSignInSignOut(object sender, EventArgs e)
{
try
{
if (btnSignInSignOut.Text == "Sign in")
{
AuthenticationResult ar = await App.PCA.AcquireTokenAsync(Constants.Scopes, GetUserByPolicy(App.PCA.Users, Constants.SignUpSignInPolicy), Constants.UiParent);
UpdateUserInfo(ar);
UpdateSignInState(true);
}
else
{
foreach (var user in App.PCA.Users)
{
App.PCA.Remove(user);
}
UpdateSignInState(false);
}
}
catch (Exception ex)
{
// Checking the exception message
// should ONLY be done for B2C
// reset and not any other error.
if (ex.Message.Contains("AADB2C90118"))
OnPasswordReset();
// Alert if any exception excludig user cancelling sign-in dialog
else if (((ex as MsalException)?.ErrorCode != "authentication_canceled"))
await DisplayAlert($"Exception:", ex.ToString(), "Dismiss");
}
}
However before I can even enter my password I get the following....
[Second image in Screenshots]
My application definition looks like this...[Third image in screenshots]
I don't think it is recognizing my tenant and trying to log me in with a Microsoft account. I have double checked my Tenant name and Application ID.
Screenshots
I don't have enough reputation to post more than one link and one picture.
Also, the Azure AD B2C api application works for a web app. I have created a web app that can authenticate and works with the API.
It looks like while modifying the authorization value in the Sample you removed the /tfp/ part.
You should update your values as follows:
public static string Authority = "https://login.microsoftonline.com/tfp/[MyTennantName].onmicrosoft.com/B2C_1_Standard_SignUpSignIn";
public static string AuthorityEditProfile = "https://login.microsoftonline.com/tfp/[MyTennantName].onmicrosoft.com/B2C_1_Standard_EditProfile";

Programmatic login with liberty profile without password

I try to migrate our application from WAS 8.0 to Liberty Profile at the moment.
In our application I need the possibility to do a programmatic login without having the password of the user.
In WAS 8.0 this was done with the following code snippet:
import com.ibm.websphere.security.auth.WSSubject;
import com.ibm.ws.security.core.ContextManagerFactory;
import com.ibm.websphere.security.auth.callback.WSCallbackHandlerImpl;
public class SecurityConfigJaasWasImpl implements ISecurityConfig {
public Object doAsWithoutPwd(String user, String[] roles, final ISecuredCode code) throws Exception {
final String mName ="doAs(String, String[], ISecuredCode)";
Object ret = null;
try {
if (code != null) {
ret = WSSubject.doAs(ContextManagerFactory.getInstance().login("REALM", user), new PrivilegedExceptionAction() {
/* (non-Javadoc)
* #see java.security.PrivilegedExceptionAction#run()
*/
public Object run() throws Exception {
return code.run();
}
});
}
} catch (LoginException e) {
throw new SecurityConfigException("Error login user " + user);
}
}
Unfortunately the class ContextManagerFactory is not known in Liberty.
All examples for programmatic login with liberty profile are using WSCallbackHandlerImpl to do a Jaas login. But for that I need to know the password of the user.
Is there any possibility to do something similar to my WAS 8.0 code in liberty profile?
I had this same problem when porting our application from WAS-ND 7 to Liberty. Unfortunately, there is no way to perform a programmatic login on Liberty without having access to the user's password. I have an open PMR with IBM on this (25293,082,000), and I was told that the feature is "under consideration". I also have an RFE open on this:
https://www.ibm.com/developerworks/rfe/execute?use_case=viewRfe&CR_ID=100438

Gmail - Web Driver Automate

Here is the code I am trying to automate Gmail through Web Driver.
I found something weird. Whenever I am commenting out the line to find the Password (Driver.findElement(By.xpath(".//*[#id='Passwd']")).sendKeys("SRS");)
then Web Driver is successfully clicking on "Sign In" button
but when I un-comment the line
(Driver.findElement(By.xpath(".//*[#id='Passwd']")).sendKeys("SRS");)
then Web Driver is not able to click on Sign In button also and it gives the error message that Unable to find the Password Xpath however still its on Email id Screen only
Here is the attached screenshot
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Gmail {
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver Driver = new FirefoxDriver();
Driver.get("https://www.google.com/gmail/about/");
Driver.findElement(By.xpath("html/body/nav/div/a[2]")).click();
Driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
//Enter the Gmail ID
Driver.findElement(By.xpath(".//*[#id='Email']")).sendKeys("RK12#gmail.com");
Driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
//Click on Next Button
Driver.findElement(By.xpath(".//*[#id='next']")).click();
Driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
Driver.findElement(By.xpath(".//*[#id='Passwd']")).sendKeys("SRS");
//Driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
}
}
1. You are giving wrong email id, hence Google validated it and shown that the error message as "Sorry, Google doesn't recognize that email".
So, enter valid email id in order to proceed to password page.
2. Here, with the code in the question, gives ElementNotVisibleException, hence added ExpectedConditions.visibilityOfElementLocated to make sure that password field is loaded before sending the keys.
Updated code:
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Gmail {
public static void main(String[] args) {
WebDriver Driver = new FirefoxDriver();
Driver.get("https://www.google.com/gmail/about/");
Driver.findElement(By.xpath("html/body/nav/div/a[2]")).click();
Driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
//Enter the Gmail ID
Driver.findElement(By.xpath(".//*[#id='Email']")).sendKeys("rbnaveen558#gmail.com");
Driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
//Click on Next Button
Driver.findElement(By.xpath(".//*[#id='next']")).click();
Driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
WebDriverWait wait = new WebDriverWait(Driver, 10);
WebElement pwd = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("Passwd")));
pwd.sendKeys("SRS");
//Driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
}
}
Please add "sign in" button also,i tested this.This is working fine.
driver.findElement(By.xpath(".//*[#id='Passwd']")).sendKeys("SRS");
driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
//click to sign in
driver.findElement(By.id("signIn")).click();

second scenario in my cucumber feature file is not executing

I'm trying to learn Cucumber with selenium java . have written two scenario's , when i run my feature file which contains two scenarios , only scenario #1 is executing , for scenario #2 its throwing Java null pointer exception
Feature: POC of my framework works
Scenario: Login test
Given I navigate to the Bugzilla website
When I click on login
And I enter the values
Then I check to see if i was successfully loged in or not
Scenario: File a bug test
Given I navigate to the File a bug page
When I click on widgets
And I enter the bug details
Then Bug should be submited succefully
My step definition file :
package cucumber.features;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
import cucumber.api.java.en.And;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
public class StepDefinitions1 {
protected WebDriver driver;
protected String baseUrl;
// Scenario 1
#Given("^I navigate to the Bugzilla website$")
public void I_navigate_to_the_Bugzilla_website() throws Throwable {
driver = new FirefoxDriver();
baseUrl ="https://landfill.bugzilla.org/bugzilla-4.4-branch/index.cgi";
driver.get(baseUrl);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
#When("^I click on login$")
public void I_click_on_login() throws Throwable {
driver.findElement(By.id("login_link_top")).click();
}
#And("^I enter the values$")
public void I_enter_the_values() throws Throwable {
driver.findElement(By.id("Bugzilla_login_top")).clear();
driver.findElement(By.id("Bugzilla_login_top")).sendKeys("jeevan.anekal#gmail.com");
driver.findElement(By.id("Bugzilla_password_top")).clear();
driver.findElement(By.id("Bugzilla_password_top")).sendKeys("testuser#123");
driver.findElement(By.id("log_in_top")).click();
}
#Then("^I check to see if i was successfully loged in or not$")
public void I_check_to_see_if_i_was_successfully_loged_in_or_not() throws Throwable {
System.out.println("Login Successfull");
}
// Scenario 2
#Given("^I navigate to the File a bug page$")
public void I_navigate_to_the_File_a_bug_page() throws Throwable {
driver.findElement(By.id("enter_bug")).click();
}
#When("^I click on widgets$")
public void I_click_on_widgets() throws Throwable {
driver.findElement(By.linkText("Widgets")).click();
}
#And("^I enter the bug details$")
public void I_enter_the_bug_details() throws Throwable {
new Select(driver.findElement(By.id("bug_severity"))).selectByVisibleText("trivial");
new Select(driver.findElement(By.id("cf_drop_down"))).selectByVisibleText("---");
new Select(driver.findElement(By.id("rep_platform"))).selectByVisibleText("Macintosh");
new Select(driver.findElement(By.id("op_sys"))).selectByVisibleText("Mac OS X 10.0");
driver.findElement(By.id("short_desc")).clear();
driver.findElement(By.id("short_desc")).sendKeys("OS crashed");
driver.findElement(By.id("comment")).clear();
driver.findElement(By.id("comment")).sendKeys("Os debugging issue");
}
#Then("^Bug should be submited succefully$")
public void Bug_should_be_submited_succefully() throws Throwable {
System.out.println("Bug submitted successfully");
}
}
Looks like you are not calling the browser and navigating to the page in scenario 2
You need do do something similar to this
#Given("^I navigate to the File a bug page$")
public void I_navigate_to_the_File_a_bug_page() throws Throwable {
driver = new FirefoxDriver();
baseUrl ="https://landfill.bugzilla.org/bugzilla-4.4-nch/index.cgi";
driver.get(baseUrl);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.findElement(By.id("enter_bug")).click();
enter code here
}
or use #Before hooks to initialize the browser
I think I kind get your problem here. I had encountered similar problem before.
So when running the feature file, either by clicking on the run button from the bar or right click in the feature file then run..., take a look at what it says when actually clicking it. Because if you hover over a certain scenario and click run, it will only run that scenario, not the whole feature file where there is more than 1 scenarios.

Shared Toast does not show in Android 3.0.1 on Motorola Xoom

I use a shared Toast across different Activities in order to only show the latest message, immediately discarding any previous ones. I put the code in the custom Application object:
public class GameApp extends Application {
private Toast mToast;
#Override
public void onCreate() {
super.onCreate();
mToast = Toast.makeText(getApplicationContext(), "", Toast.LENGTH_SHORT);
}
public void displayToast(int textId) {
displayToast(getText(textId));
}
public void displayToast(CharSequence text) {
mToast.cancel();
mToast.setText(text);
mToast.show();
}
}
The Toast showed up on my 1.6, 2.2, and 3.0 emulators. But when I downloaded the released app from the Market, it only shows on my G1 (CyanMod 6.1) but not Xoom (3.0.1). I tried connecting the Xoom with USB debugging, but nothing relevant showed up in LogCat.
Prior to this, I used to do Toasts the conventional way (i.e. via Toast.makeText()) and that worked on everything as expected.
Could there be any potential problem with my above code, or could this be a bug in the Xoom? Here is the link to my app, in case you want to test it. The Toast should show up when you click Today, Progress in the Main screen. I appreciate any help. Thank you very much :)
i'm not sure but the sdk that motorola uses may be different.. and mToast.cancel() could be doin something terrible.. so have you tried this..
public void displayToast(CharSequence text) {
mToast.setText(text);
mToast.show();
}
This is because that mToast.cancel(); may close the toast if it's showing, or don't show it if it isn't showing yet.
Please create new Toast object when users click buttons. And keep the previous Toast object reference. Next time when user click buttons, cancel the previous Toast object and create new Toast again.
public class GameApp extends Application {
private Toast mToast;
private Context mContext;
#Override
public void onCreate() {
super.onCreate();
mToast = Toast.makeText(getApplicationContext(), "", Toast.LENGTH_SHORT);
}
public void displayToast(int textId,Context mContext) {
this.mContext = mContext;
displayToast(getText(textId));
}
public void displayToast(CharSequence text) {
mToast.cancel();
mToast = new Toast(mContext);
mToast.setText(text);
mToast.setDuration(Toast.LENGTH_SHORT);
mToast.show();
}
}

Resources