How to get rid of new empty chrome window that opens up while running in headless mode - selenium-chromedriver

I have a selenium/gauge automation project and using java for the code. In my driver factory, I have it set to run headless, however; when I run it, an empty chrome window launches for some reason. How can I make it stop launching this window?
public static WebDriver getDriver() {
String browser = System.getenv("BROWSER");
if (browser == null) {
WebDriverManager.chromedriver().setup();
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setJavascriptEnabled(true);
ChromeOptions options = new ChromeOptions();
options.addArguments("chrome.switches","disable-extensions", "ignore-certificate-errors", "no-sandbox");
options.addArguments("--disable-popup-blocking"); //Global driver.switchTo().alert().accept();
options.addArguments("start-maximized");
options.addArguments("headless");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
return new ChromeDriver(capabilities);
}
public class AppLauncher {
public static String APP_URL = System.getenv("APP_URL");
#Step("Launch Qualitrac")
public void launchQualitrac() {
webDriver.get(AppLauncherObjects.getMapPageNames().get("Qualitrac"));
assertEquals("Qualitrac", webDriver.getTitle());
}
}
public class Driver {
// Holds the WebDriver instance
public static WebDriver webDriver;
public static HashMap globalStash;
// Initialize a webDriver instance of required browser
// Since this does not have a significance in the application's business domain, the BeforeSuite hook is used to instantiate the webDriver
#BeforeSuite
public void initializeDriver() {
webDriver = DriverFactory.getDriver();
webDriver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
globalStash = new HashMap<String,String>();
}
// Close the webDriver instance
#AfterSuite
public void closeDriver(){
webDriver.quit();
}
}

could you replace :
options.addArguments("headless");
With :
options.addArguments("--headless");

Related

swing application opens and closes down immediately when invoked with assertJ command (TestNG + assertJ Swing)

Trying assertJ-swing for UI testing of java-swing based application.
Situation: Sample application in JavaApp.java (with Main class) works fine when it is invoked from this java file (running it as Java application). But when it is invoked from TestNG with assertj-swing's command:
application(JavaApp.class).start();
the application opens up but closes down immediately.
Question: Is it the only approach? Please suggest resolution or any other approach to launch the application and keep it open so further operations can be performed.
JavaApp:
package jdialogdemo;
import java.awt.*;
import java.awt.event.*;
import javax.lang.model.util.SimpleElementVisitor6;
import javax.swing.*;
public class JavaApp {
public static void main(String[] args) throws Exception {
final JFrame frame = new JFrame("JDialog Demo");
final JButton btnLogin = new JButton("Click to login");
btnLogin.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e) {
LoginDialog loginDlg = new LoginDialog(frame);
loginDlg.setVisible(true);
// if logon successfully
if(loginDlg.isSucceeded()){
btnLogin.setText("Hi " + loginDlg.getUsername() + "!");
}
}
});
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(700, 200);
frame.setLocationRelativeTo(null);
frame.setLayout(new FlowLayout());
frame.getContentPane().add(btnLogin);
frame.setVisible(true);
}
}
AssertJ-Swing verifies that you only do access swing components on the EDT (as required because Swing is not thread safe, see Concurrency in Swing - Initial threads).
Your main method violates this (by constructing the UI from the main thread) and therefore AssertJ-Swing fails with an exception.
To correct the problem your main method should look like this:
public class JavaApp {
public static void main(String[] args) throws Exception {
SwingUtilities.invokeLater(() -> {
final JFrame frame = new JFrame("JDialog Demo");
final JButton btnLogin = new JButton("Click to login");
//...
});
}
}

MvvmCross Tab navigation raises exception Trying to show a tab without a TabBarViewController, this is not possible

I'm trying to create tab navigation in iOS project using latest MvvmCross 5.x., but I'm getting the exception saying:
"Trying to show a tab without a TabBarViewController, this is not possible!"
Can anyone explain, what could be wrong, or is there any example simple project to show how tab navigation works using new latest MvvmCross 5.x version in iOS projects?
This is my code:
[Register("MainView")]
[MvxRootPresentation(WrapInNavigationController = true)]
public class MainView : MvxTabBarViewController<MainViewModel>
{
}
[MvxTabPresentation]
public partial class HomeView : MvxViewController<HomeViewModel>
{
}
public class IosViewPresenter : MvxIosViewPresenter
{
public override void Show(IMvxIosView view, MvxViewModelRequest request)
{
// This line gets called, but raises exception complaining that TabBarController is null.
base.Show(view, request);
}
}
[Register ("AppDelegate")]
public class AppDelegate : MvxApplicationDelegate
{
public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
{
Window = new UIWindow(UIScreen.MainScreen.Bounds);
var setup = new Setup(this, Window);
setup.Initialize();
var start = Mvx.Resolve<IMvxAppStart>();
start.Start();
setup.EnsureInitialized(GetType());
Window.MakeKeyAndVisible();
return true;
}
}
public class Setup : MvxIosSetup
{
protected override IMvxIosViewPresenter CreatePresenter()
{
var viewModelLoader = new MvxViewModelLoader();
Mvx.RegisterSingleton<IMvxViewModelLoader>(() => viewModelLoader);
var presenter = new IosViewPresenter((MvxApplicationDelegate)ApplicationDelegate, Window, viewModelLoader);
Mvx.RegisterSingleton<IMvxIosViewPresenter>(presenter);
return presenter;
}
}

Elements disappear after pause and resume

Testing my libGDX app in RoboVM, I have encountered a major problem. When I pause my app (by actually going to the Home screen or sending app invites via Facebook) and then return to my app, classes of my games disappear. As if it does not store data properly on the resume() method. First i though it there was a problem of my AssetLoader, but after some debugging I found that the situation is worse. Actual instances of classes and shapes disappear. As if they never existed.
After googling the issue, I found that it might be related to IOSGraphics, but I have not managed to fix the problem.
My IOSLauncher looks something like this, I have erased the Facebook & Google AdMob specific code.
protected IOSApplication createApplication() {
IOSApplicationConfiguration config = new IOSApplicationConfiguration();
config.useAccelerometer = true;
config.useCompass = true;
config.orientationPortrait = true;
config.orientationLandscape = false;
return new IOSApplication(new Game(this), config);
}
#Override
public boolean didFinishLaunching(UIApplication application,
UIApplicationLaunchOptions launchOptions) {
FBSDKApplicationDelegate.getSharedInstance().didFinishLaunching(application, launchOptions);
initialize();
return true;
}
public void initialize() {
//...
}
public static void main(String[] argv) {
NSAutoreleasePool pool = new NSAutoreleasePool();
UIApplication.main(argv, null, IOSLauncher.class);
pool.close();
}
#Override
public void showAds(boolean show) {
//...
}
#Override
public void shareOnFacebook() {
//...
}
#Override
public void inviteFriends() {
//....
}
#Override
public boolean openURL(UIApplication application, NSURL url,
String sourceApplication, NSPropertyList annotation) {
super.openURL(application, url, sourceApplication, annotation);
return FBSDKApplicationDelegate.getSharedInstance().openURL(
application, url, sourceApplication, annotation);
}
#Override
public void didBecomeActive(UIApplication application) {
super.didBecomeActive(application);
FBSDKAppEvents.activateApp();
}
#Override
public void willResignActive(UIApplication application) {
super.willResignActive(application);
}
#Override
public void willTerminate(UIApplication application) {
super.willTerminate(application);
}
}
This sounds similar to a threading bug I once encountered. I fixed it by deferring resize and resume but I'm not sure if it will help in your case. Something like this:
private boolean needResize, needResume;
private void resize (int width, int height){
needResize = true;
}
private void deferredResize ();
if (!needResize) return;
needResize = false;
int width = Gdx.graphics.getWidth();
int height = Gdx.graphics.getHeight();
//move your resize code here
}
private void resume (){
needResume = true;
}
private void deferredResume (){
if (!needResume) return;
needResume = false;
//move your resume code here
}
public void render (){
deferredResize();
deferredResume();
//...
}
I suggest that you start looking for an alternative to RoboVM to avoid more issues in the future, as Robovm was acquired by Microsoft Xamarin (sad but true) and the framework is no longer maintained. License keys (with Libgdx) will continue to work until the 17th of April 2017, there will be no further updates to RoboVM, be it new features or bug fixes.
As far as I know, Libgdx will switch to Multi-OS engine as the default iOS backend for newly created libGDX projects in the next couple of weeks.
After a couple of days filled with headache I found the solution!
LifeCycle methods like pause & resume, hide & show are not always called When they are supposed to be called, therefore data is not stored properly. This issue can completely break your game.
This thing only occurred when testing my game on the iOS platform, mainly when I opened a 3rd party app, Facebook in this case. No such thing found on Android, though.
The only thing I changed on the iOS version was calling the mentioned methods manually to make sure it always pauses and resumes when it has to.

how to play swf file in standalone adobe flash player in html5

I have to play shockwave file in stand alone adobe flash player not in web browser and that shockwave file too contains xml file as content in it. all suggestions are welcomed please
Google just launched a new Google Labs project called “Swiffy“. It converts Flash SWF files to HTML5.
It lets you reuse Flash content on devices without a Flash player (ie: iPhones and iPads).
sourced by : http://www.webpronews.com/convert-swf-files-to-html5-with-swiffy-2011-06
import java.io.File;
import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
public class ReadHtml implements Runnable {
private static String flashFileName = "";
private static String flashXmlName = "";
private static String flashString = "";
private static String flashPlayer = "flashplayer_11_sa";
private static String htmlFilePath = "";
public final static void main(String[] args) throws Exception {
File file = new File("D:/.../index.html");
Document doc = null;
Element link = null;
if (file.exists()) {
htmlFilePath = file.getParent();
doc = Jsoup.parse(file, "UTF-8", "");
link = doc.select("embed").first();
}
flashXmlName = link.attr("flashvars");
flashFileName = link.attr("src");
flashString = flashFileName + "?" + flashXmlName;
flashString = htmlFilePath + File.separator + flashString;
Thread CmdThread = new Thread(new ReadHtml());
CmdThread.start();
}
#Override
public void run() {
try {
final String[] cmdArray = { flashPlayer, flashString };
final Process process = Runtime.getRuntime().exec(cmdArray);
process.waitFor();
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
}

Selenium 2 and JUnit4: How to capture screenshot on exception?

I want to capture a screenshot only upon unexpected exception.
Note.- This answer could be outdated. The answer is based on Selenium 2.15
Using TestWatcher does the trick (the unit test must extend following BaseTest):
public abstract class BaseTest {
// ...
protected WebDriver driver;
#Rule
public TestRule testWatcher = new TestWatcher() {
#Override
public void starting(Description desc) {
LOG.info("Launching browser...");
driver = Utils.getFirefoxDriver();
}
#Override
public void finished(Description desc) {
LOG.info("Quitting driver...");
driver.quit();
}
#Override
public void failed(Throwable e, Description d) {
LOG.debug("Creating screenshot...");
File scrFile = ((TakesScreenshot) driver).getScreenshotAs(
OutputType.FILE);
String scrFilename = "Screenshot.png";
File outputFile = new File(SCREEN_SHOTS_RESULTS_PATH, scrFilename);
LOG.info(scrFilename + " screenshot created.");
try {
org.​apache.​commons.​io.FileUtils.copyFile(scrFile, outputFile);
} catch (IOException ioe) {
LOG.error("Error copying screenshot after exception.", ioe);
}
}
};
}
Note
Utils.getFirefoxDriver() returns a customized WebDriver. Something like:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
public class Utils {
// ...
public static WebDriver getFirefoxDriver() {
FirefoxProfile firefoxProfile = new FirefoxProfile();
// Profile customization. For example:
// firefoxProfile.addExtension("firebug-1.8.4-fx.xpi");
// firefoxProfile.setPreference("extensions.firebug.currentVersion","1.8.4");
FirefoxBinary firefox = new FirefoxBinary();
// Firefox customization. For example:
// firefox.setEnvironmentProperty("DISPLAY", display);
WebDriver driver = new FirefoxDriver(firefox, firefoxProfile);
// WebDriver customizations. For example:
// driver.manage().timeouts().implicitlyWait(SHORT_TIMEOUT_S, TimeUnit.SECONDS);
return driver;
}
}