TestStack / TestStack.Seleno

Seleno helps you write automated UI tests in the right way by implementing Page Objects and Page Components and by reading from and writing to web pages using strongly typed view models.
http://teststack.github.com/TestStack.Seleno/
MIT License
180 stars 60 forks source link

automated UI tests: Find.Element issue #246

Open wijdenchebbi opened 8 years ago

wijdenchebbi commented 8 years ago

Hello,

I have a problem in my UI Tests: i used Find.Element(By.LinkText()) and Find.Element(By.CssSelector()) and The tests run fine in local (VS2012 ASP.Net project) but when i deploy my tests in the server i reseive the errors of buid in some tests: Information: [Error] 'TestStack.Seleno.PageObjects.Actions.ElementFinder' Error invoking ElementFinder.Element Information: [Error] 'TestStack.Seleno.PageObjects.Actions.ElementFinder' OpenQA.Selenium.NoSuchElementException: Unable to locate element: {"method":"css selector","selector":""} at TestStack.Seleno.Extensions.WebDriverExtensions.ElementWithWait(IWebDriver driver, Func`2 elementIsFound, TimeSpan maxWait)

Information: [Error] 'TestStack.Seleno.PageObjects.Actions.ElementFinder' OpenQA.Selenium.NoSuchElementException: Unable to locate element: {"method":"LinkText"} at TestStack.Seleno.Extensions.WebDriverExtensions.ElementWithWait(IWebDriver driver, Func`2 elementIsFound, TimeSpan maxWait)

I tried to run the tests in different versions of Visual Studio 2012,2013, and 2015 and i find the same error of build but in different tests.

I don't know why find.element doesn't work sometimes?

Thanks.

robdmoore commented 8 years ago

What is running the tests on the build server? TeamCity? VSTS? ...?

Does it always fail on the build server or is it intermittent?

Have you added code to take screenshots? What do the screenshots show?

On 25 Apr 2016, at 5:05 am, wijdenchebbi notifications@github.com wrote:

Hello,

I have a problem in my UI Tests: i used Find.Element(By.LinkText()) and Find.Element(By.CssSelector()) and The tests run fine in local (VS2012 ASP.Net project) but when i deploy my tests in the server i reseive the errors of buid in some tests: Information: [Error] 'TestStack.Seleno.PageObjects.Actions.ElementFinder' Error invoking ElementFinder.Element Information: [Error] 'TestStack.Seleno.PageObjects.Actions.ElementFinder' OpenQA.Selenium.NoSuchElementException: Unable to locate element: {"method":"css selector","selector":""} at TestStack.Seleno.Extensions.WebDriverExtensions.ElementWithWait(IWebDriver driver, Func`2 elementIsFound, TimeSpan maxWait)

Information: [Error] 'TestStack.Seleno.PageObjects.Actions.ElementFinder' OpenQA.Selenium.NoSuchElementException: Unable to locate element: {"method":"LinkText"} at TestStack.Seleno.Extensions.WebDriverExtensions.ElementWithWait(IWebDriver driver, Func`2 elementIsFound, TimeSpan maxWait)

I tried to run the tests in different versions of Visual Studio 2012,2013, and 2015 and i find the same error of build but in different tests.

I don't know why find.element doesn't work sometimes?

Thanks.

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub

wijdenchebbi commented 8 years ago

Hi Robdmoore the tests are running by a powershell script : VSTest On the build server:it is intermittent, And i didn't use the screenshots, how can i use it?

Thanks,

wijdenchebbi commented 8 years ago

Hi,

I test the devexpress GridView loading: How can i add Wait.Until the loading of the callback is completed.

I used WaitFor.AjaxCallsToComplete(); but i get this error: $ is undefined (UnexpectedJavaScriptError)

robdmoore commented 8 years ago

That'll be because you don't have jQuery loaded on the page. Some of the things in Seleno like the waitfor.ajaxcallstocomplete depend on jQuery being there.

The fact it's intermittent probably means it's a timing issue. It may happen on the build server rather than local because the build server is a bit slower so things take longer to load.

If you want to put in a wait until a particular element is there then look into the WebDriverWait class (it's part of Selenoium.WebDriver, which Seleno wraps.

wijdenchebbi commented 8 years ago

Thanks for your reply,

In fact, i get the issue of JavaScriptError in local not in the build server.

In the server build, i had another issue of find element: i replaced it by wait.Until(ExpectedConditions.ElementIsVisible(By.Id("id")));but it didn't work

So, i used the way to execute javascript code to click into the element: IJavaScriptExecutor js = (IJavaScriptExecutor)BrowserHost.Instance.Application.Browser; js.ExecuteScript("return document.getElementsByClassName('classname')[0].click();");

And this time it works correctly in the server build :)

Now, i have the same error of WaitFor.AjaxCallsToComplete(); just in local

I tried to use another way to verify that the document is ready and the ajax call are completed by this code: WebDriverWait wait = new WebDriverWait(BrowserHost.Instance.Application.Browser, TimeSpan.FromSeconds(100)); wait.Until(d => (bool)(d as IJavaScriptExecutor).ExecuteScript("return document.readyState").ToString().Equals("complete")); wait.Until(d => (bool)(d as IJavaScriptExecutor).ExecuteScript("return jQuery.active == 0")); and i got an error( jQuery is not a function (UnexpectedJavaScriptError))

It can be related to the navigator FireFox or the speed of the connexion?

Thanks.