I am new to appium and using its version 1.7
i have to long press a webelement in my native app on android version 7.0
It shows all the methods are depreciated except for longPress(LongPressOptions longpressoptions) and longPress(PointOption longpressoptions).
so i started using it like below
I am using it like below
public static RemoteWebDriver driver;
driver = new RemoteWebDriver(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);
WebElement homeScrSwipe = driver.findElementById("pulldown_image");
TouchAction ta = new TouchAction((PerformsTouchActions) driver);
ta.longPress(homeScrSwipe, Duration.ofMillis(5000)).release().perform();
but it always gives me below error
The method longPress(WebElement, Duration) from the type TouchAction is deprecated.
If someone could let me know what is this longPressOptions in both the methods that would be of great help
Try this code
it may help you
TouchAction ta = new TouchAction(driver);
ta.longPress(x,y).moveTo(x,y).release().perform();
longPress(x,y) are Coordinates of mobile screen and moveTo(x,y) are to how many points you want swipe
for appium 1.7.1
android java client jar 5.0.4
Happy Testing
WebElement webElement = appiumDriver.findElement(By.xpath(element));
TouchAction Action = new TouchAction(appiumDriver);
// Action.longPress(webElement).perform();
Action.longPress(webElement).release().perform();
public static void touchDown(MobileElement element) {
new TouchAction(AppiumDriverCapabilitiesUtilities.driver).longPress(element2).release().perform();
}
TouchAction action1 = new TouchAction(((MobileDriver) Driver));
action1.longPress(LongPressOptions.longPressOptions().withElement(ElementOption.element(Element))).waitAction(WaitOptions.waitOptions(Duration.ofMillis(500))).release();
Related
I am newbie using Winium and installed a sample test - steps are only to open Notepad and click on the File button/menu item. The launching of the application (Notepad) works but it seems it can not locate the button. I have tried to locate using both name and id attributes without any luck. I am running on Windows 10 so my guess is it has something to do with this..Any tips or workarounds highly appriciated - i will pase my simple code below
Thanks!
public static void main(String[] args) throws MalformedURLException, InterruptedException {
DesktopOptions option = new DesktopOptions();
option.setApplicationPath("C:\\Windows\\System32\\notepad.exe");
WiniumDriver driver = new WiniumDriver(new URL("http://localhost:9999"), option);
Thread.sleep(2000);
WebElement el = driver.findElement(By.name("File"));
el.click();
}
You could try getting a reference to the window first, and then looking within that for an element called 'File'.
This works for me.
var window = driver.FindElementByClassName("Notepad");
var fileMenuHeader = window.FindElement(By.Name("File"));
fileMenuHeader.Click();
I'm not sure how you get the next level of menus though - it doesn't appear to be part of the window.
Try catching the menu-bar first with its ID.
Then with that element try catching the menu options like file, edit,etc.
Below code works fine on Windows 10.
var menubar = Driver.FindElementById("MenuBar");
var editMenu = menubar.FindElement(By.Name("Edit"));
var FileMenu = menubar.FindElement(By.Name("File");
editMenu.Click();
I am using White Framework for automation. when I trying to get desktop instance I got exception "The type initializer for 'White.Core.Desktop' threw an exception."
My code looks like :
var window = White.Core.Desktop.Instance.Windows().Find(obj => obj.Title.Contains("TestAppHome"));
Is there any way to capture the window without exception that is without using White.Core.Desktop class?
Any help would be greatly appreciated !
Try this one:
List<White.Core.UIItems.WindowItems.Window> windows = WindowFactory.Desktop.DesktopWindows();
var window = windows.Find(w => w.Title.Contains("TestAppHome"));
Try this. You can directly launch the target application and get it's UI elements rather than search all UI elements in Desktop. I think this is very efficient.
static void Main(string[] args)
{
Application app = Application.Launch(#"C:\Testing\Sample.txt"); //Target application
var appWindow = app.GetWindow("Sample - Notepad");
appWindow.RightClick();
PopUpMenu popupMenu = appWindow.Popup;
var saveOptionMenuItem = popupMenu.ItemBy(SearchCriteria.ByText("Open IME"));
saveOptionMenuItem.Click();
}
I'm using GWT 2.6.0 and I'm following the StockWatcher tutorial.
Simplified, this is my code:
private Button sendButton = new Button("send");
private VerticalPanel mainPanel = new VerticalPanel();
public void onModuleLoad(){
// this works
mainPanel.add(sendButton);
RootPanel.get("stockList").add(mainPanel);
// until I add a Click Handler:
sendButton.addClickHandler(event -> addStock());
}
private void addStock(){
//TODO: implement
}
The button is not rendered. However, if I remove the click handler, the button becomes visible.
I'm completely new to GWT and I'm wondering what I'm doing wrong here?
I'm using ant devmode to run in development mode and I'm using Firefox 26.0.
I not sure, that gwt 2.6 supports java8 and lambdas.
To be convinced of this, try to compile you project to javascript.
Java 7 is supported and is now the default. (This can be overridden
using
-sourceLevel 6)
http://www.gwtproject.org/release-notes.html#Release_Notes_2_6_0
It looks like that lamdas a java8 feature are not supported yet by GWT:
sendButton.addClickHandler(event -> addStock());
Here's how to add a click handler
Button b = new Button("Click Me");
b.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
// handle the click event
}
});
We are using 1.4.9 for our current webapp. But we want to upgrade to higher 1.4.x version preferably 1.4.22(latest 1.4). The problem is that the page won't submit if AjaxButton is clicked. This is working in 1.4.9. I put breakpoint on the onSubmit of that button but it is not going there. Any insights on this? Thanks!
Here is the code:
For the button:
public abstract class SXIButton extends AjaxButton {
public SXIButton(String id, Form form) {
super(id, form);
initialize();
add(new SimpleAttributeModifier("validating", "false"));
}
}
In the java:
searchForm.add(new SXIButton("searchButton", searchForm) {
private static final long serialVersionUID = -4366670520053224476L;
#Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
LOG.info("Searching Users");
target.addComponent(userContainer);
userSearchModel.setUserCurrentUserFilter(getSessionBOUser().getCd());
UserDataProvider udp = new UserDataProvider(userSearchModel,isForSearch);
udp.setSort("cd", true);
userContainer.addOrReplace(getResultPanel(udp));
}
});
add(portlet);
portlet.add(searchForm);
in html
<input type = "submit" wicket:id = "searchButton" wicket:message="value:button.search" />
Without any code it's hard to help you out. I would first check the changelog to see if anything was changed in a later version that might causes you trouble (e.g. this ticket). If you cannot find anything obvious you might want to update first to another version which is not the latest one, to narrow down in which version your code breaks for the first time.
But those are just shots in the dark.
I want to write a simple HTMLUnit test script for Jenkins (former Hudson). INFO: Jenkins uses the YUI Javascript library. The YUI library replaces the form submit with a custom button. The script just creates a new job in Jenkins.
start Jenkins:
java -jar jenkins.war
Current versions of HTMLUnit do not support form.submit any more and require you to use button.click() for form submitting. Unfortunately this does not work for Jenkins (the sample below does not advance the page and create the job but stays on the new job page)
I tried for some hours now to find a solution or workaround but so far I could not get the form submitted. Hopefully somebody has found a solution and let me know.
Here is my sample code:
package example;
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
import com.gargoylesoftware.htmlunit.html.HtmlButton;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlInput;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
public class jenkins3 {
public static void main(String args[]) {
// create a new job in jenkins
// home
final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_3_6);
try {
final HtmlPage page1 = webClient.getPage("http://localhost:8080");
//assertEquals("Dashboard [Jenkins]", page1.getTitleText());
// new job
final HtmlAnchor new_job = page1.getAnchorByText("New Job");
final HtmlPage page2 = new_job.click();
// job name
HtmlTextInput name_field = (HtmlTextInput) page2.getElementById("name");
name_field.type("new job by htmlunit");
// radio button
final HtmlInput radio_freestyle = (HtmlInput) page2.getByXPath("//input[#value='hudson.model.FreeStyleProject']").get(0);
radio_freestyle.click();
Thread.sleep(10000);
// OK button (submit form)
final HtmlForm form = page2.getFormByName("createItem");
//final HtmlSubmitInput button = (HtmlSubmitInput) form.getByXPath("//button").get(0);
final HtmlButton button = (HtmlButton) form.getByXPath("//button").get(0);
final HtmlPage page3 = button.click(); // !!!!! Form submit does not workstacko
//assertEquals("Dashboard [Jenkins]", page3.getTitleText());
}
catch( Exception e ) {
System.out.println( "General exception thrown:" + e.getMessage() );
e.printStackTrace();
}
webClient.closeAllWindows();
}
}
Although this may be completely out of the question in your senerio: i would suggest giving up on HTMLUnit. I've had bug after bug, mainly because of the pages I've been automating tests for aren't always 100% valid html (3rd party piggybacked requests). I finally went looking elsewhere and found PhantomJS (js bindings to the WebKit engine) much better suited.
For me the advantages were evident:
- no need for another app server
- much simpler and faster to script JS than Java
- a "real"-world engine is more realistic than a buggy emulator one
Thats my advice,
Cheers
HTMLUnit doesn't include support for testing javascript actions. You might not want to switch your testing framework at this point, but I would recommend using Selenium for this kind of testing. It runs a mock browser and executes javascript, making it possible to do this sort of thing.
I have found this little trick to work. Navigate to the Jenkins login page using HtmlUnit. Add a Submit button to the login form. Set appropriate attributes to Submit element, including an "onclick" value. Click on this new button and viola! You're logged in.
Note, if you're not concerned about security, you can also do this:
webClient.getPage("https://yourdomain:8443/jenkins/j_acegi_security_check?j_username=yourUsername&j_password=yourPassword");
See below for first method.
Enjoy,
Nick.
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
public class JenkinsLogin {
final String urlValue = "https://<yourdomain>:8443/jenkins";
private final String userName = "yourUsername";
private final String password = "yourPassword";
protected static final BrowserVersion BROWSER_VERSION_FIREFOX = new BrowserVersion(
"Netscape", "5.0 (Windows)",
"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20100101 Firefox/8.0",
(float) 1.2);
private final WebClient webClient = new WebClient(BROWSER_VERSION_FIREFOX);
public static void main(final String[] args) throws Exception {
final JenkinsLogin jenkinsLogin = new JenkinsLogin();
jenkinsLogin.login();
}
private void login() throws Exception {
this.webClient.setThrowExceptionOnScriptError(false);
HtmlPage page = this.webClient.getPage(this.urlValue + "/login");
final HtmlForm form = page.getFormByName("login");
form.getInputByName("j_username").setValueAttribute(this.userName);
form.getInputByName("j_password").setValueAttribute(this.password);
final HtmlElement createdElement = page.createElement("input");
createdElement.setAttribute("type", "submit");
createdElement.setAttribute("name", "submitIt");
createdElement.setAttribute("onclick", "login.submit();");
form.appendChild(createdElement);
final HtmlElement submitButton = form.getInputByName("submitIt");
page = submitButton.click();
final HtmlElement loginField = page.getFirstByXPath("id('login-field')");
if (loginField == null || !loginField.getTextContent().contains(this.userName))
throw new RuntimeException("Unable to log on to Jenkins. ");
System.out.println("Logged in! ");
}
}
Does replacing
final HtmlButton button = (HtmlButton) form.getByXPath("//button").get(0);
final HtmlPage page3 = button.click()
with
form.submit((HtmlButton)last(form.getHtmlElementsByTagName("button")));
work?