Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have one question - how to write a cucumber hook that asserts the web URL.
Example -
Let's say I am testing - https://www.usatoday.com/tech/
My Given is as follows -
Given I am on the "/tech/" page
I would like a method to add the base url (www.usatoday.com) + "/tech" and assert whether it is currently on that page
(driver.getURL() ==www.usatoday/tech/)
otherwise navigate to that page if I am not there.
Any Java pros that can help me with this? Many thanks my friends.
#Given("^I am on the \"([^\"]*)\" page$")
public void i_am_on_the_page(String arg) throws throwable{
String newBaseURL = getBaseURL() + arg;
String currentURL = driver.getCurrentURL();
try{
Assert.assertEquals(newBaseURL, currentURL);
}
catch(Exception e){
driver.get(newBaseURL);
}
}
I am assuming that you have a function - getBaseURL() that will provide you the base url.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 9 days ago.
Improve this question
My API response gets doubled every time I refresh my page. Is it because my return object is declared outside and every time I refresh it creates a new entry?
#GetMapping(value = "/getPaymentMethodDetails")
public List<AutoPayAccountBean> executePaymentMethodDetails(HttpServletRequest request) {
executeGetPaymentMethodsForUser(request);
if (Objects.nonNull(getPaymentMethodsList())) {
getPaymentMethodsList().stream().forEach(paymentMethod -> {
AutoPayAccountBean accountBean = new AutoPayAccountBean();
accountBean.setPaymentMethod(paymentMethod.getProfileName());
accountBean.setExpirationDate(expirationDate);
accountBean.setHolder(paymentMethod.getHolder());
accountBean.setStatus(paymentMethod.getStatus());
this.paymentMethodResponse.add(accountBean);
});
}
return paymentMethodResponse;
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I just wanted to know how can I execute a specific action when a User navigates to an URL inside a Webview, for Example something like:
if (URL == https://google.com) {
execute Action
You need to setWebViewClient to override the urls like below -
webView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if ( url.startsWith("https://google.com")){
// your action
}
});
Hope this will help you.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have a java selenium program that automatically presses on a button in a website. The code i am using looks like this :
driver.findElement(By.id("button")).click();
I want the program to use if statements if possible.
Thanks for your help.
Use can use findelements by along with if to achieve this. Below code might give you some idea.
if(driver.findElements(by.xpath("//*[#id=253]")).size>0)
{
//element exists with id = 253
// do the stuff
} else
{
//element do not exist with id = 253.
// do the stuff
}
Hope this helps. Thanks.
You may try this:
public void ClickButton () throws InterruptedException
{
WebElement button = driver.findElement(By.id("button"));
String Source = driver.getPageSource();
if (Source.contains(button))
{
button.click();
Thread.sleep(3000);
}
else
{
driver.quit;
}
}
Hope this can be helpful. Let me know if you are still facing problem.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
In my Test script have to write waiFor(5) for every excution, else Test fails.
Am using POM, and have separate class.
#Test(priority=2)
public void TestMedical() throws InterruptedException {
waitFor(5);
MedicalPage medicalpage = new MedicalPage(driver);
waitFor(5);
medicalpage.PhysicianName(Repo.getProperty("fName"));
medicalpage.seteditableLastName(Repo.getProperty("lName"));
waitFor(5);
medicalpage.setPhone(Repo.getProperty("Phone"));
waitFor(5);
medicalpage.setEmail(Repo.getProperty("Email"));
}
This is my Login Page (Object)-
// Created methods in this page, and using Testng trying to call all the below methods. But getting failure message Unable to Locate Element, If there is no wait time watFor(5). With Wait time its running fine.In base page have explicit wait time method, but its not working. After input the data in text field when i click on submit button page is doing some Java Script or Ajax.
Ajax call takes 60 sec max.
driver.findElement(firstName).click();
driver.findElement(editableFirstName).clear();
driver.findElement(editableFirstName).click();
driver.findElement(editableFirstName).sendKeys(fName);
}
Added try - catch, works fine now
WebElement element = driver.findElement(XYZ);
boolean clicked = false;
do{
try {
element.click();
} catch (WebDriverException e) {
continue;
} finally {
clicked = true;
}
} while (!clicked);;
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
My application contains an upload option from which the user can upload files(any file).
I know that users have the ability to write code/scripts in excel worksheet.So how can i prevent that from happening as it can lead to security breach.
Or what check can i apply to know that the uploaded worksheet contains any function?
I assume from the Java tag that your appliction to which the sheet gets uploaded is a Java application.
Using Apache POI, you can use a POIFSReader (see this doc) to read the file on a lower level.
There is an example by RĂ©al Gagnon which shows how you can check the content by looking at the name.
I had to modify the listener (added another comparision)
class MacroListener implements POIFSReaderListener {
[...]
#Override
public void processPOIFSReaderEvent(POIFSReaderEvent event) {
System.out.println(" Event: Name " + event.getName() + ", path "
+ event.getPath());
if (event.getPath().toString().startsWith("\\Macros")
|| event.getPath().toString().startsWith("\\_VBA")
|| event.getPath().toString().contains("_VBA_")) {
this.macroDetected = true;
}
}
}
so that it worked for some test files. You might have to tune/extend the checks.