SeleniumHQ / selenium-google-code-issue-archive

Archive, please see main selenium repo
https://github.com/seleniumhq/selenium
345 stars 195 forks source link

Web driver confuse on submit url, if each step of test case call a function defined in another file. #6064

Closed lukeis closed 8 years ago

lukeis commented 8 years ago

Originally reported on Google Code with ID 6064

Web driver is getting confuse when calling function for each steps of test case. Webdriver
picks some other url on submit while actual url on submit is different. This is happening
when each step of test case call a function defined in another file.

What steps will reproduce the problem?
1. Write your code in two java files.
2. Use one Java file to declare functions and second to define functions.
3. In second file, where you have defined functions, use selenium code.
4. For example:
Take a site where you can book hotels.
Now, you need to pass City name, from date, to date and then click on submit button
to start search.

File1.java
-declare function for "city name", send city name in parameters to calling function
which is defined in file2.java
-Define another function for "from date"send from date in parameters to calling function
which is defined in file2.java
-Define another function for "to date"send to date in parameters to calling function
which is defined in file2.java
-Define another function to submit form.
No parameter required just send just call submit function defined in file2.java.

Now, at the time of submit Selenium webdriver will confuse and will re-direct you webpage
to some other different page.

Sample:
1. File1.java

public void ExecuteTestCase() {
TestCaseRead = TestReadExcel();
ComFun.AppURL(((ArrayList)TestCaseRead.get(0)).get(0));
ComFun.LandingPageSearch(((ArrayList)TestCaseRead.get(0)).get(1));      ComFun.LandDatesFrom(((ArrayList)TestCaseRead.get(0)).get(2));
ComFun.LandDatesTo(((ArrayList)TestCaseRead.get(0)).get(3));
ComFun.SubmitForm();
}

File2.java
public class CommonFunctions implements Driver{

//Constructor
public CommonFunctions() { 
        //Max OS X - Chrome
        //System.setProperty("webdriver.chrome.driver", "/Users/ashv/Automation/Selenium/AshDataDriven/BrowserNativeDriver/chromedriver");
        //Windows - Chrome
        //System.setProperty("webdriver.chrome.driver", "F:\\Automation\\Lib\\Chrome\\chromedriver.exe");
    }

    //Selenium: Test Data for Search on Landing page
    public void LandingPageSearch(Object TestAction) {
        WebElement  datavalue = Driver.findElement(By.name("rs_city"));
        datavalue.clear();
        datavalue.sendKeys((String)TestAction);
        datavalue.submit();
    } 

    //Selenium: Hit URL of application
    public void AppURL (Object TestAction) {
        Driver.get((String) TestAction);
    }

    //Selenium: Landing Page Dates
    public void LandDatesFrom( Object TestAction) {
        WebElement LandDateF = Driver.findElement(By.name("rs_chk_in"));
        LandDateF.clear();
        LandDateF.sendKeys((String)TestAction);
    }
    public void LandDatesTo( Object TestAction) {
        WebElement LandDateT = Driver.findElement(By.name("rs_chk_out"));
        LandDateT.clear();
        LandDateT.sendKeys((String)TestAction);
    }

    //Selenium: Submit Form
    public void SubmitForm() {
        WebElement Submit = Driver.findElement(By.cssSelector("button.search")); 
        Submit.submit();
    }

What is the expected output? What do you see instead?
=======

Selenium version: 2.28 (Web driver)
OS: MAC OX 10.8.2 and Windows 7 
Browser: Chrome / Firefox 
Browser version: Firefox 12, Chrome 11

Reported by ashv.sharma on 2013-08-08 07:13:38

lukeis commented 8 years ago
Please send questions about test code architecture to the selenium user list [1]

[1] https://groups.google.com/forum/#!forum/selenium-users

Reported by barancev on 2013-08-08 07:28:48

lukeis commented 8 years ago
barancev: This code is working fine if I took all function in single fine.
This rule out the fact that code have some issues.
As far as architecture concerned agreed this might not be standard way to develop some
app/project/framework but my concerned is: whatever way I have implemented follows
Java OOPs rule. I am not violating any Java rule and any Java code will run based on
the approached I followed.

Certainly I can follow up with Selenium user forum, but I am not convenience that architecture
issue causing Selenium webdriver to pick another URL rather than expected one. 

Actually, once you click on submit button on site, than application is designed to
perform two action on one submit button. And webdriver is picking second url while
expected to pick first url. (Second url option is not visible on UI, so manually none
of the user can not hit second url, but selenium is doing.)

I understand this is open forum and you have control on it.
I can not discuss more on this issue and convince you more as your decision will be
having more weight-age and my issue is a edge case.

Reported by ashv.sharma on 2013-08-08 10:27:50

lukeis commented 8 years ago
You say this is a bug. However, you've not shown us where we can go to reproduce the
same thing.

I'd also kindly ask why are you using an old version of Selenium? You mentioned two
OS'es...which one does this happen on?

You mention the "submitting form gets confused"...by this I assume when you run "SubmitForm()"...so
the first thing to try is to ensure it's the element you expect it and also check there
are no other elements matching the same selector.

So I'd make:

    Driver.findElement(By.cssSelector("button.search")); 

into:

    Driver.findElements(By.cssSelector("button.search")); 

and verify what comes back from this .findElements call, is *only* ONE element.

Reported by arran.huxtable on 2013-08-08 10:51:37

lukeis commented 8 years ago
Please attach a complete executable code sample to reproduce the issue. Otherwise the
issue will be closed, sorry.

Reported by barancev on 2013-08-08 13:26:21

lukeis commented 8 years ago
Sorry for delay, Please find the attached code to re-produce this issue.
Attached two java file (CommonFunctions.java and TestCaseExecutor.java).

I have removed extra stuff from code to make it simplify.
Note: 
-I have confirmed with latest webdriver 2.34 as well, still facing same issue.
-I found same issue with one public site (http://www.nextravel.com/) that I used in
the attached example to re-produce this issue.

Points:
-I am not able to debug it further since its breaking at selenium internal code workflow.
-This is working fine, if I place all called and calling functions in a single file.
However, if I break code in two files (called functions and calling functions) issue
raised.
-Webdriver gets deviate from actual submit url to some other url after placing second
to date value on main page. (i.e. after calling function  following //ComFun.LandDatesTo("10/6/2013");
attached in java file.)

Expected output:
After submit button user should get to re-direct to following search page:
http://search.nextravel.com/

Actual results:
After submit button user is getting redirect to following search page:
http://hotelsbycity.hotelplanner.com

Reported by ashv.sharma on 2013-08-09 20:26:02


lukeis commented 8 years ago
When I do the same actions manually on the site http://www.nextravel.com/ I get to the
page http://hotelsbycity.hotelplanner.com/GroupForm.cfm?DestinationSearchString=New%20York%20City,%20NY&CheckInDate1=8/6/2013&OutDate=10/6/2013&Rooms=1&GroupType=170&es=1

Reported by barancev on 2013-08-10 06:17:43

lukeis commented 8 years ago
Please close this issue. I got it.
My BAD. Mark it as invalid, I agreed.

Reported by ashv.sharma on 2013-08-10 07:43:03

lukeis commented 8 years ago

Reported by barancev on 2013-08-10 08:04:51

lukeis commented 8 years ago

Reported by luke.semerau on 2015-09-17 18:17:41