Can I write a code in groovy in wait for page load? - katalon-studio

I'm using Winium automation tool for desktop apps that is integrated with Katalon Studio but I'm using static wait time, like Thread.sleep().
Sometimes page load is taking more than the time what I'm putting there.
So is there any way to use groovy code that will wait until the application loads successfully?

In two ways, we can solve this issue
one increase the wait for page load option in Katalon
WebUI.waitForPageLoad(10, FailureHandling.STOP_ON_FAILURE);
Else use the custom fluent wait
Wait wait = new FluentWait(driver)
.withTimeout(30, SECONDS)
.pollingEvery(5, SECONDS)
.ignoring(NoSuchElementException.class);
WebElement foo = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("object details")));

Related

protractor : Best way to use in protractor ? driver.get("URL") or browser.get("URL")

Which is best way to use in protractor ?
var driver = browser.driver;
driver.get("URL")
or
browser.get("URL")
browser.manage().timeouts().implicitlyWait(browser.params.implicitWaitTime);
Currently I have used second approach to open URL and perform any browser action. Should I change everything like first approach or my approach is nice to go ahead ?
My two cents
If its a non angular application - go For browser.driver.get()
If not go for browser.get('')
browser.get understands the angular cycle and waits for the angular activity to finish
from documentation - API Documentation
Navigate to the given destination and loads mock modules before
Angular. Assumes that the page being loaded uses Angular. If you need
to access a page which does not have Angular on load, use the wrapped
webdriver directly.
If you are using browser.get() then you dont need a implicit wait and ideally you should avoid using it

Protractor, Javascript: How to kill all existing browsers

I am writing an application for end to end testing using Protractor for an angular 2 application.
Before starting my application I would like to close all browsers that may be running on my machine. e.g. when I am running my test in chrome, I want to close all chrome processes/instances before my test starts.
So, looking for something that I may call in beforeLaunch method of protractor config. (please let me know if there is a better place to call it with the answer of how to do it)

Not able to click link text in selenium web driver execuiton

I am trying to click hyperlink called "order create" in my application.I have used following code.When I execute this step in eclipse debug mode or selenium IDE, I am able to click particular link.However when I try to execute via Java mode in eclipse, my code is not able to click this link.Do we have any other option to click this link?(i.e wait and click something)
Driver.findElement(By.xpath(//*[#href='link' and text()='Create Order'])).click();
You can use explicit wait with expected condition elementToBeClickable to wait for the element to be clickable
WebDriverWait wait = new WebDriverWait(Driver, 10);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[#href='link' and text()='Create Order']"))).click();
Hi if your drivers clicks before page load then there is a synchronization issue
simplest way to avoid synchronization issue is use of universal wait i.e implicit wait which says driver instance to wait for a maximum of defined (time seconds) before sending any error.
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
in above code you are telling driver instance to wait a maximum of 20 seconds for the individual webelements in the current session.Note above wait is applicable for all webelements.
I have used Thread.sleep(2000); before my test step.It has solved my issue.

GWT Selenium Tests sometimes fails

we currently have a nice problem with our selenium tests in a gwt powered gui.
The application contains two sections (filter and grid). Our tests sometimes fails with a NoSuchElementException.
Crazy is the following: I stop the test in eclipse with a breakpoint and inspect the page with firefox firebug or any other addon. And okay - I cannot find the desired element. But (without restarting the application or any other changes in eclipse), if i try again and search the element it is there and a resume in eclipse the test goes green. For me it seems like a synchronize problem in firefox.
A explicitly wait command
new WebDriverWait(getDriver(), 10).until(condition);
has the only effect, that the timeout (10 seconds) happens.
As I said - sometimes the test is green and sometimes it fails.
Has anybody an idea?
Sounds like you load some data asynchronous (RPC) from the server? The data and thus the element which presents the data in the UI is not there yet, when Selenium is looking for it. Depending on how long your queries take on the database or what latency you have on the network the wait time may vary from test-run to test-run.
I have a workaround for this problem and would share this.
The following piece of code is executed before the explicit wait command is running.
Window window = getDriver().manage().window();
Dimension dimension = window.getSize();
Dimension tmp = new Dimension(dimension.getWidth() - 1, dimension.getHeight());
window.setSize(tmp);
window.setSize(dimension);
I figured out, that the DOM is in "synchronized" state after the browser window is resized. So I decrement the width and than set it back to the old value.
If anybody has a better suggestion - let us know ;-)

Testing with dual UI's

I have a browser based test program for testing a browser based application. This means that I need to record sequences that alternately manipulate the test program and then the application to check that it reacts correctly, so that I can perform automated testing.
How should I do this with SAHI?
I cannot see a way of recording two separate URL's concurrently. I have tried combining the two UI's using frames, and iframes, but I couldn't get SAHI to record in the frame/iframe.
I could modify the test program so that I can call it from scripts called by SAHI, but that rather defeats the object of having an automation tool...
Any suggestions?
1) Record the actions on the first web page using Sahi (script1)
2) Record the actions on the second web page (script2)
3) In script1, do this
// do steps for UI 1 as recorded in script1
_call(window.open("second url", "newWindow")); // open the second window
_selectWindow("newWindow"); // target the following steps on newWindow
// copy steps from script2 here
_selectWindow(); // return to base window
// perform further base window steps
// Use _selectWindow("newWindow") and _selectWindow() to switch between windows.
Hope this helps.
Regards,