Clicking button in Vaadin application has no effect with Selenium WebDriver - selenium-webdriver

I'd like to interact with a Vaadin application (Vaadin 8) using WebDriver. The login form is wrapped using the PageObject pattern.
#Test
public void login() {
driver.get("http://localhost:8080/intern/login");
LoginPage loginPage = new LoginPage(driver);
loginPage.enterUserCredentials("test", "test");
loginPage.submit();
}
The submit() method finds the login button and triggers a .click().
#FindBy(id = "loginButton")
private WebElement loginButton;
public void submit() {
this.loginButton.click();
}
When using the "real" application the click triggers several requests and responses to/from the server until the next page after the login page is loaded.
In the above WebDriver example however nothing happens after the click although I instructed the driver to do an implicit wait.
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

Related

Authentication Window Alert is working in IE11 but not working in Chrome v60

In my scenario, when I launch a URL, an authentication alert window opens up and I need to enter Username and Password from excel and on clicking on 'Log In' it'll show me the web homepage. I've implemented this using the below code snippet and it's working perfectly in IE11. But when I'm trying to run the same code in Chrome v60, it's not working. It's showing the authentication alert window but not performing any action on it. Screenshot attached. Can anyone suggest please.
Selenium WD version - 3.4.0
Code:
public static void loadApplicationURL(WebDriver driver) throws Exception
{
String SSPathl = null;
String URL = Generic_Functions.GetParameterFromInputSheet("URL");
try
{
driver.get(URL);
Thread.sleep(6000);
LoginApplication.isAlertPresent(driver);
}
}
public static boolean isAlertPresent(WebDriver driver) {
try {
driver.switchTo().alert();
UserAndPassword UP = new UserAndPassword(UserName,Password);
driver.switchTo().alert().authenticateUsing(UP);
Thread.sleep(8000);
return true;
}
catch (Exception e) {
return false;
}
}
For test browsers, have created a separate class. Find below the snippet used for IE and Chrome browsers.
For Chrome
System.setProperty("webdriver.chrome.driver",".\\Resources\\chromedriver.exe");
driver = new ChromeDriver()
In case of IE,
[System.setProperty("webdriver.ie.driver",".\\Resources\\IEDriverServer.exe");
DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
ieCapabilities.setCapability("nativeEvents", true);
driver = new InternetExplorerDriver(ieCapabilities);][1]

Libstreaming: How to navigate from SurfaceView screen(Sending Video+Audio Streams to wowza) to HTML Page in Android Phonegap

I am creating one phonegap application using Libstreaming for Video and Audio streaming. I have login and Home screen. On Home screen, there is a button "Start Streaming", on click of this button It launches the camera to start streaming which sends audio and video streams to WOWZA media server. The camera preview has one surface view on which video is getting played.
The camera preview has one Back button over SurfaceView to back on Home screen. My issue is that, On click of back button Camera preview should be destroyed and It should redirect to Home screen (Navigation from Android SurfaceView to HTML page).
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/surface_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:background="#android:color/black" >
<!-- Below surface view is used to to send rtsp audio+video stream to wowza server -->
<net.majorkernelpanic.streaming.gl.SurfaceView
android:id="#+id/surface_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center" />
<!-- button to halt the camera preview and go back on to the main screen -->
<Button
android:id="#+id/btnGoBack"
android:layout_width="60dp"
android:layout_height="40dp"
android:visibility="visible"
android:text="Back"
android:layout_alignTop="#+id/surface_view"
android:layout_alignParentLeft="true"
android:textSize="14dp"
/></RelativeLayout>
I have done it myself. It looks big but quite simple. All you need to do is, define a click method of back button (which is on the SurfaceView) in your activity class (Not MainActivity as follows-
public class LiveStreamingActivity extends Activity implements RtspClient.Callback, Session.Callback, SurfaceHolder.Callback {
private static SurfaceView mSurfaceView;
private Button btnGoBack;
private SurfaceHolder mHolder;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
if (!LibsChecker.checkVitamioLibs(this))
return;
mSurfaceView = (SurfaceView) findViewById(R.id.surface_view);
btnGoBack = (Button) findViewById(R.id.btnGoBack);
mHolder = mSurfaceView.getHolder();
mHolder.addCallback(this);
/* click listener of back button */
btnGoBack.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
try {
MainActivity.isFirstTime = true;
/* on click of back button finish the current activity
* which will destroy the surfaceview and will go back on MainActivity
* by referring the Android Activity lifecycle, OnResume() method of MainActivity
* would be called where you can call javascript function directly.
*/
finish();// callback lifecycle: "onPause", "onStop", and at last "onDestroy"
} catch (Exception e) {
e.printStackTrace();
}
}
});
}}
MainActivity.java:
You have to declare a field ("isFirstTime = false") to put a logic for calling javascript function in OnResume() method. (For better understanding please refer Android activity lifecycle).
public class MainActivity extends CordovaActivity {
public static boolean isFirstTime = false;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
loadUrl(launchUrl);
}
#Override public void onResume(){
super.onResume();
System.out.println("onResume main activity");
if(isFirstTime){System.out.println("Inside onResume");
loadUrl("javascript:launchProfile()");
}
}
#Override public void onPause(){
super.onPause();
System.out.println("onPause main activity");
isFirstTime = false;
}}
Javascript Function:
I am using AngularJS. So I have to get the $location object to inject the path of profilePage.
function launchProfile(){
var e = document.getElementById('loginScreen');/*'loginScreen' is login form id */
var $injector = angular.element(e).injector();
var $location = $injector.get('$location');
$location.path("/profilePage");}
app.js (Angularjs routing):
vcApp = angular.module('VCMobApp', ['ngRoute']);vcApp.config(['$routeProvider', function ($routeProvider){
$routeProvider.when('/', {templateUrl: 'screens/login.html', controller: 'loginPageCntrl' });
$routeProvider.when('/profilePage', {templateUrl: 'screens/profilePage.html', controller: 'profilePageCntrl'});
$routeProvider.otherwise({ redirectTo: '/' });}]);
In case you are not using AngularJS, then directly you can call your html page using window.location.href='../profilePage.html' inside launchProfile() function itself (skip angularjs code then).

Selenium web driver scripts for Authenticated view

I am new for Automation testing using selenium web driver for chrome.I want to test authenticated view from selenium web driver ,so i wrote code
public void WriteReviewAfterLogin()
{string BaseUrl = "http://vps65937-6.lcnservers.com/10300/profile/login.php";
var driver = new ChromeDriver();
driver.Navigate().GoToUrl(BaseUrl);
var loginBox = driver.FindElement(By.Id("username"));
loginBox.SendKeys("govinda.silverlight#gmail.com");
var pwBox = driver.FindElement(By.Id("password"));
pwBox.SendKeys("12345");
var signinBtn = driver.FindElement(By.CssSelector("[class='btn btn-default signin']"));
signinBtn.Click();
const string url = "http://vps65937-6.lcnservers.com/10300/company-reviews/sks-security-53beee89163ce.html";
driver.Navigate().GoToUrl(url);
((IJavaScriptExecutor)driver).ExecuteScript("window.resizeTo(1024, 768);");
var reviewTitle = driver.FindElement(By.Id("review_title"));
reviewTitle.SendKeys("thi is testing titile");
var review = driver.FindElement(By.Id("review"));
review.SendKeys("this is testing");
var signinBtns = driver.FindElement(By.CssSelector("[class='submitReview']"));
signinBtns.Click();
driver.Navigate().GoToUrl("http://vps65937-6.lcnservers.com/10300/");
}
invoked as
private static void Main(string[] args)
{
SeliniumChrome loginSeliniumChrome=new SeliniumChrome();
loginSeliniumChrome.WriteReviewAfterLogin();
}
When this code runs the login view is authenticated and redirected to another url,the login state is lost how to set in log in state in that case.
I don't find any use of below mentioned lines in your code. Better to remove these lines because once you will login you will be redirected to below mentioned url.
const string url = "http://vps65937-6.lcnservers.com/10300/company-reviews/sks-security-53beee89163ce.html";
driver.Navigate().GoToUrl(url);

Soundcloud mobile auth with Google+ returns a blank page?

I'm having issues with trying to sign in via Google on the SoundCloud authorize page (www.soundcloud.com/connect). When a user tries to auth with that, they see a blank page and they are not redirected back to the app. It works fine for the Facebook sign in and regular user/pass sign in.
If you are using WebView the problem is it doesn't support popup windows, and they are required by the auth flow. Got it to work by implementing popup support along the lines of https://stackoverflow.com/a/8022295.
private void setUpWebView() {
webView = new WebView(getContext());
webView.setWebChromeClient(new MyChromeClient());
final WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setSupportMultipleWindows(true);
webView.loadUrl(url);
}
...
final class MyChromeClient extends WebChromeClient {
// Add new webview in same window
#Override
public boolean onCreateWindow(WebView view, boolean dialog,
boolean userGesture, Message resultMsg) {
WebView childView = new WebView(getContext());
childView.getSettings().setJavaScriptEnabled(true);
childView.setWebChromeClient(this);
childView.setLayoutParams(FILL);
mContent.addView(childView);
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
transport.setWebView(childView);
resultMsg.sendToTarget();
return true;
}
// remove new added webview whenever onCloseWindow gets called for new webview.
#Override
public void onCloseWindow(WebView window) {
mContent.removeViewAt(mContent.getChildCount() - 1);
}
}

Not able to Click a Link in Gmail using Selenium Webdriver

I am a learner.
I am trying to automate the logout functionality of Gmail using Selenium Webdriver but unable to do so ..
There are two Phases in logout, first click the Right Link at the top, if that box appears then click logout. iam unable to do so.
<span id="gbi4t" style="max-width: 76px; text-align: left;">Mahmood Ali</span>
<a id="gb_71" class="gbqfbb" href="?logout&hl=en&hlor" onclick="gbar.logger.il(9,{l:'o'})" role="button" target="_top">Sign out</a>
here is my xpath
//*[#id="gbi4t"] -> Clicking that top to get the logout pop up
//*[#id="gb_71"] -> To logout the gmail application
i have tried such as
driver.findElement(By.id("gbi4t")).click(); OR
driver.findElement(By.xpath("//*[#id='gbi4t']")).click();
driver.findElement(By.id("gb_71")).click(); OR
driver.findElement(By.xpath("//*[#id='gb_71']")).click();
Some ideas out there ?
Actually the <span> isn't recognized as an element.
You need to use the <a id="gbg4" ...> to click() on it, wait the pop up and click on the <a id="gb_71" class="gbqfbb" ...> to logout.
I let you code, since you need to pracctice :P
tell me what's up.
Suggestions :
What i can suggest to you is to use the cssSelector().
why ? Because it's faster than the xpath and when page like google or others use dynamic value used for id/name it's better to use the class attribute and cssSelector() is way better than others.
But sometimes you'll use xpath to find an element that has "cancel" as inner text (exemple : <a>cancel</a> )
cssSelector() reference
You can also try following:
driver.find_element(:id, "gbgs4dn").click
driver.find_element(:id, "gb_71").click
This worked for me.
This code certainly works for me:
// (after logging to google.com)
WebDriverWait wait = new WebDriverWait(driver, timeoutInSeconds);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("gbi4t")));
//open overlay
driver.findElement(By.id("gbi4t")).click();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("gb_71")));
//press logout
driver.findElement(By.id("gb_71")).click();
Heres a solved example ::
package testme;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class testexample {
public static WebDriver driver;
public static WebElement element;
public static void main(String args[]) throws InterruptedException {
//setting the chrome driver
System.setProperty("webdriver.chrome.driver", "C:/Users/workspace/Downloads/chromedriver.exe");
driver = new ChromeDriver();
driver.get("http://www.gmail.com");
element =driver.findElement(By.linkText("Sign in"));
element.click();
Thread.sleep(1000);
element = driver.findElement(By.id("Email"));
element.sendKeys("yourusername#gmail.com");
element = driver.findElement(By.id("Passwd"));
element.sendKeys("yourpassword");
element.submit();
Thread.sleep(1000);
//click on the logout link step 1
element = driver.findElement(By.xpath("//*[#id='gb']/div[1]/div[1]/div/div[3]/div[1]/a"));
element.click();
// click on actual logout button step 2
element = driver.findElement(By.id("gb_71"));
element.click();
//closing the webdriver window after successful completion of the test
driver.close();
}
}

Resources