I have developed a Flutter chat. Now I am trying to do test with UI automator but setText method for Edit Text not work.
UI Automator Viewer app
This is for a Windows 10 with Android Studio.
I have a class where I define the objects
public class ChatAppObjects {
public static UiObject ICON_CHATAPP = new UiObject(new UiSelector().className("android.widget.TextView").text("ChatApp"));
public static UiObject TXT_MESSAGE = new UiObject(new UiSelector().className("android.widget.EditText"));
public static UiObject BTN_SEND = new UiObject(new UiSelector().className("android.widget.Button"));
}
And this is the test
public void test1() throws UiObjectNotFoundException, InterruptedException {
UiDevice mDevice = UiDevice.getInstance();
mDevice.pressHome();
ChatAppObjects.ICON_CHATAPP.clickAndWaitForNewWindow();
ChatAppObjects.TXT_MESSAGE.click();
ChatAppObjects.TXT_MESSAGE.clearTextField();
ChatAppObjects.TXT_MESSAGE.setText("Prueba");
ChatAppObjects.BTN_SEND.click();
}
Test run successful but not write "Prueba" into textbox
Flutter apps do not work with UiAutomator. The only way to run integration tests on them right now is with flutter's own testing utility. You can read about getting started with it here.
Related
Here is my Desktop Launcher code:
public class DesktopLauncher {
public static void main (String[] arg) {
Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration();
config.setForegroundFPS(60);
config.setTitle("Game10");
config.setWindowedMode(1240, 760);
config.forceExit = false; // ERROR!!!
new Lwjgl3Application(new GdxGame10(), config);
}
}
In new LWJGL3 config.forceExit not working. I can't find any solution so far. Any help is appreciated.
There is no forceExit in config. So presumably you have a master application that runs a child libGDX component and when you end that child component you find that the entire application shuts down, when you want the master application to continue. I guess you are on desktop because Android would be OK. So you must want to avoid a full System.exit
i.e.
Gdx.app.exit()
shuts down everything.
So when you instantiate a libGDX application you instantiate based on the application type, so for me, I use the same as you
final Lwjgl3Application application = new Lwjgl3Application(Services.GAME_CONTROLLER,config);
and the implementation for exit is
#Override
public void exit () {
running = false;
}
This finished the while loop that drives the application i.e. kills the main thread. If you have -other threads- running in the background they keep going.
If on the other hand you were instantiating LwglAWTCanvas then your shutdown would be this.
#Override
public void exit () {
postRunnable(new Runnable() {
#Override
public void run () {
stop();
System.exit(-1);
}
});
}
which would shut down the entire application. Anyway so forceExit being -false- was to stop a full system exit killing all your threads. The forceExit was to "force" the other threads to finish. It doesn't do that anymore so the fact it is now missing should not matter, your background threads should keep going.
In other words, config.forceExit = false; is now the default behaviour for your application type so you don't need it.
I am new to automation and want to create an automation test which can do following:
Open one tab --- click and get some info from that tab
Switch to another tab --- click and get some info from this tab now.
Compare the infos.
We use Page Object Model to get info from one page. However the moment, I switch to another tab -- it switches the tab successfully but does not locate any element on it.
Any idea ?
Questions I would ask is,
Is the element locator correct?
Is this a unique element locator?
Is this a synchronization issue? Are you waiting enough for the page to load before finding the element?
Is this problem particular to a browser? Is it consistent across?
Also make sure you pass on the driver object from one page object to the other. Like,
public class PageOne {
public PageOne(WebDriver driver) {
//do something in constructor
}
public void someMethodInPage1() {
driver.findElement(By.id("button1")).click();
PageTwo pageTwo = new PageTwo(driver);
pageTwo.someMethodInPage2();
}
}
public class PageTwo {
private WebDriver driver;
public PageTwo(WebDriver driver) {
//do something in constructor
this.driver = driver;
}
public void someMethodInPage2() {
driver.findElement(By.id("button2")).click();
}
}
I have an Air application. It consist of an HTML component. I create a flex application and launch this application in HTML component of Air Application. I am able to capture the trace output of Air application but I can not capture trace output of flex application. As this flex application is launched in Air application's HTML component. I use vizy that output the log prints. How can I capture the trace output of flex web application. Thanks
One possible solution, use mx.logging.Log for debug traces and custom LogTarget to capture them.
It would go something like this. Declare the necessary objects:
private var logTarget:MyLogTarget= new MyLogTarget();
private var myLog:ILogger;
Set up logging where you initialize the application:
myLog=Log.getLogger("MyApp");
Log.addTarget(logTarget);
Log stuff:
myLog.info("Something something.");
myLog.warn("This is weird!");
myLog.error("This shouldn't happen!");
The meat of the solution is the custom log target, MyLogTarget.as:
package
{
import mx.logging.LogEvent;
import mx.logging.targets.LineFormattedTarget;
public class MyLogTarget extends LineFormattedTarget
{
public var log:Vector.<String>=new Vector.<String>;
public function MyLogTarget()
{
super();
}
override public function logEvent(event:LogEvent):void
{
trace(event.message);
log.push(event.message+"\n");
}
}
}
This particular implementation just stores all traces in a vector of Strings, but you can modify it to save the log to disk, send it to a service, trace it on screen or whatever works for you.
I use selenium RC. My tests are failed after waiForPageToLoad() method. It doesn't find element on the page. I see on my browser what page is still loading while waiForPageToLoad() "said" that page is already loaded. How can I check how looks my HTML code just after waiForPageToLoad() method finished its execution?
One more thing. In one of occasions Element which sould be finded after waiForPageToLoad() is between the
<h1><script language="Javascript" </script>
<a id="some" class="some" onclick="">Text</a>
Text
</h1>
So could be that page is loaded but javascript is not yet executed. How to fix this?
1) waiForPageToLoad() does not prove that you have all elements on the page. It is better to use waitForElementPresent, or check isElementPresent to find out if the element is on the page.
2) you did not mention what language you use in RC.
if java - you may use
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
...
public void captureScreen(String fileName) throws Exception {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Rectangle screenRectangle = new Rectangle(screenSize);
Robot robot = new Robot();
BufferedImage image = robot.createScreenCapture(screenRectangle);
ImageIO.write(image, "png", new File(fileName));
}
if C#:
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using NUnit.Framework;
using Selenium;
using System.Drawing;
using System.Drawing.Imaging;
namespace SeleniumTests
{
[TestFixture]
public class ImageCapture
{
private ISelenium selenium;
private StringBuilder verificationErrors;
public static string CaptureScreenshot()
{
Bitmap bmpScreenshot = new Bitmap(1024, 768, PixelFormat.Format32bppArgb);
Graphics Screenshot = Graphics.FromImage(bmpScreenshot);
Screenshot.CopyFromScreen(0, 0, 0, 0, new Size(1024, 768));
string name = (System.Convert.ToString(System.DateTime.Now).Replace("/", "_")).Replace(":", "_") + ".jpg";
bmpScreenshot.Save(name, ImageFormat.Jpeg);
return name;
}
3) if you develop in java - consider using Sikuli. It is a tool that works with images on the screen (you may use as java library). You may combine Selenium and Sikuli to get fantastic flexibility and functionality.
I developed some JUnit tests that extend org.apache.struts2.StrutsTestCase. I used the tutorial on struts.apache.org as my starting point.
Everything was working fine until I modified my simple web application to use Tiles. I have Tiles working fine in the app but now my Action test cases have stopped working.
I'm getting NullPointerException at org.apache.struts2.views.tiles.TilesResult.doExecute when I run the following line of code:
ActionProxy proxy = getActionProxy("/displaytag.action");
The log shows the Struts 2 Action is executing succesfully until it tries to hand it off to TilesResult.doExecute.
I suspect it is because the tests run outside of the container and the tiles.xml is only referenced in the web.xml and therefore my StrutsTestCase tests don't know where to find the definitions in tiles.xml.
Is this making sense?
I'm using Struts 2.2.1.1 and the tiles related jars (v. 2.0.6) included in the Struts distribution.
I'll include a code snippet from my StrutsTestCase but please note everything runs successfully when I run the app from the browser in Tomcat, it only fails when I run the StrutsTestCase outside of Tomcat. And the test cases ran successfully before I added Tiles.
public class TagActionTest extends StrutsTestCase {
static Logger logger = Logger.getLogger(TagActionTest.class);
public void testCreateTagFail() throws Exception {
logger.debug("Entering testCreateTagFail()");
try {
request.setParameter("name", "");
ActionProxy proxy = getActionProxy("/createtag.action");
TagAction tagAction = (TagAction) proxy.getAction();
proxy.execute();
assertTrue("Problem There were no errors present in fieldErrors but there should have been one error present", tagAction.getFieldErrors().size() == 1);
assertTrue("Problem field 'name' not present in fieldErrors but it should have been",
tagAction.getFieldErrors().containsKey("name") );
} catch (Exception e) {
logger.debug("Error running testCreateTagFail()");
e.printStackTrace();
assertTrue("Error running testCreateTagFail()", false);
}
}
Partial stack trace:
java.lang.NullPointerException
at org.apache.struts2.views.tiles.TilesResult.doExecute(TilesResult.java:105)
at org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:186)
at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:373)
Lastly, can anyone explain what the deal is with StrutsTestCase? There's a tutorial page for using it with Struts 2 on struts.apache.org but the SourceForge page for it hasn't been updated since Struts 1.3 Also, what's the difference between StrutsTestCase and MockStrutsTestCase
I imagine you're initialising tiles with a listener:
<listener>
<listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
</listener>
You need to initialise that Listener in your tests. I found a few others with the same issue [1].
The code below is in your class that extends StrutsSpringTestCase. You need to override the setupBeforeInitDispatcher. In the code snippet below, the override sets the applicationContext attribute (also needed if you're using spring) and initialises Tiles (inside the if(tilesApplication) segment, where tilesApplication is a boolean so you can toggle this code on an off based on your whether or not your application runs with tiles ):
/** Overrides the previous in order to skip applicationContext assignment: context is #autowired
* #see org.apache.struts2.StrutsSpringTestCase#setupBeforeInitDispatcher()
**/
#Override
protected void setupBeforeInitDispatcher() throws Exception {
//init context
servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, applicationContext);
if(tilesApplication){
servletContext.addInitParameter(BasicTilesContainer.DEFINITIONS_CONFIG, "WEB-INF/tiles.xml");
final StrutsTilesListener tilesListener = new StrutsTilesListener();
final ServletContextEvent event = new ServletContextEvent(servletContext);
tilesListener.contextInitialized(event);
}
}
[1] See http://depressedprogrammer.wordpress.com/2007/06/18/unit-testing-struts-2-actions-spring-junit/
It is trying to display the jsp page. So disable by adding ExecuteResult(false) in the code.
So, add the below line
proxy.setExecuteResult(false);
before proxy.execute()