When it is important to write Selenium Code

classic Classic list List threaded Threaded
35 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Re: When it is important to write Selenium Code

Adrien007
Sorry its not working.
Browser doesn't respond that is understandable but its not even launching the browser.
Something's wrong here or we are missing.
Do me favor screencast a video where you record play simple google search and then paste the code in eclipse to run same test on different browsers.
Here's the Jing of what I tried:
http://screencast.com/t/Ve8OqAhPvQS
Reply | Threaded
Open this post in threaded view
|

Re: When it is important to write Selenium Code

softwaretestingforum
Administrator
I saw there was a failure but you did not highlight what the failure was.

Can you past the class here what you are using in your screencasts?
~ seleniumtests.com
Reply | Threaded
Open this post in threaded view
|

Re: When it is important to write Selenium Code

Adrien007
package com.example.tests;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

import java.util.concurrent.TimeUnit;

import org.junit.After;
import org.testng.annotations.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.BeforeClass;

public class CrossBrowser {
        private WebDriver driver;
        private String baseUrl;
        private StringBuffer verificationErrors = new StringBuffer();
        @BeforeClass(alwaysRun=true)
        public void setUp() throws Exception {
                driver = new FirefoxDriver();
                baseUrl = "www.google.com";
                driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        }

        @Test
        public void testCrossBrowser() throws Exception {
                // open | http://www.google.co.in/#hl=en&sugexp=crf&cp=4&gs_id=w&xhr=t&q=java&pf=p&sclient=psy-ab&site=&source=hp&pbx=1&oq=java&aq=0&aqi=g4&aql=f&gs_sm=&gs_upl=&bav=on.2,or.r_gc.r_pw.,cf.osb&fp=e7c9e9e102ade5dc&biw=762&bih=746 |
                driver.get("http://www.google.co.in/#hl=en&sugexp=crf&cp=4&gs_id=w&xhr=t&q=java&pf=p&sclient=psy-ab&site=&source=hp&pbx=1&oq=java&aq=0&aqi=g4&aql=f&gs_sm=&gs_upl=&bav=on.2,or.r_gc.r_pw.,cf.osb&fp=e7c9e9e102ade5dc&biw=762&bih=746");
                // assertTitle | java - Google Search |
                assertEquals("java - Google Search", driver.getTitle());
                // type | id=lst-ib | java
                driver.findElement(By.id("lst-ib")).clear();
                driver.findElement(By.id("lst-ib")).sendKeys("java");
                // verifyTextPresent | The Java™ Tutorials |
                // ERROR: Caught exception [ERROR: Unsupported command [isTextPresent]]
                // click | css=a.kl |
                driver.findElement(By.cssSelector("a.kl")).click();
                // assertTitle | java - Google Search |
                assertEquals("java - Google Search", driver.getTitle());
                // verifyTextPresent | logo |
                // ERROR: Caught exception [ERROR: Unsupported command [isTextPresent]]
        }

        @After
        public void tearDown() throws Exception {
                driver.quit();
                String verificationErrorString = verificationErrors.toString();
                if (!"".equals(verificationErrorString)) {
                        fail(verificationErrorString);
                }
        }

        private boolean isElementPresent(By by) {
                try {
                        driver.findElement(by);
                        return true;
                } catch (NoSuchElementException e) {
                        return false;
                }
        }
}
Reply | Threaded
Open this post in threaded view
|

Re: When it is important to write Selenium Code

softwaretestingforum
Administrator
While I am debugging your script. Also paste the stack trace of error you encountered with last execution.
~ seleniumtests.com
Reply | Threaded
Open this post in threaded view
|

Re: When it is important to write Selenium Code

Adrien007
[TestNG] Running:
  C:\Users\pushpraj.singh\AppData\Local\Temp\testng-eclipse--489922267\testng-customsuite.xml

FAILED CONFIGURATION: @BeforeClass setUp
java.lang.NoClassDefFoundError: com/google/common/base/Function
        at com.example.tests.CrossBrowser.setUp(CrossBrowser.java:22)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
        at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:550)
        at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:212)
        at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
        at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:175)
        at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:107)
        at org.testng.TestRunner.privateRun(TestRunner.java:758)
        at org.testng.TestRunner.run(TestRunner.java:613)
        at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
        at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
        at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
        at org.testng.SuiteRunner.run(SuiteRunner.java:240)
        at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
        at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:87)
        at org.testng.TestNG.runSuitesSequentially(TestNG.java:1170)
        at org.testng.TestNG.runSuitesLocally(TestNG.java:1095)
        at org.testng.TestNG.run(TestNG.java:1007)
        at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:109)
        at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:202)
        at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:173)
Caused by: java.lang.ClassNotFoundException: com.google.common.base.Function
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 25 more

SKIPPED: testCrossBrowser

===============================================
    Default test
    Tests run: 1, Failures: 0, Skips: 1
    Configuration Failures: 1, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 1, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 0
===============================================

[TestNG] Time taken by org.testng.reporters.XMLReporter@133796: 14 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@1e4cbc4: 8 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter@4741d6: 9 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@b166b5: 42 ms
[TestNG] Time taken by [TestListenerAdapter] Passed:0 Failed:0 Skipped:0]: 14 ms
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@c2a132: 75 ms
Reply | Threaded
Open this post in threaded view
|

Re: When it is important to write Selenium Code

softwaretestingforum
Administrator
In reply to this post by softwaretestingforum
I just executed your script and I saw Google search for word "java".

But you don't even see browser launching. With your last video there were failures.
What were those failures? Did you analyze the stack trace to debug it.
~ seleniumtests.com
Reply | Threaded
Open this post in threaded view
|

Re: When it is important to write Selenium Code

softwaretestingforum
Administrator
In reply to this post by Adrien007
Did you notice this line?

Pushpraj Singh wrote
[TestNG] Running:
  C:\Users\pushpraj.singh\AppData\Local\Temp\testng-eclipse--489922267\testng-customsuite.xml
What is this file - "testng-customsuite.xml"?
TestNG is using this file to execute tests. And not the method name which you do right click on and execute.
Do you understand issue now?
 
~ seleniumtests.com
Reply | Threaded
Open this post in threaded view
|

Re: When it is important to write Selenium Code

Adrien007
No I dont understand , I dont know how this file is there?
I have now deleted this file from this path and run the code via testng but it is still showing that path in top.
-I dont know the significance of this file and dont know is this responsible  that test is failing?
-How to rectify this and run the code sucessfully??
Reply | Threaded
Open this post in threaded view
|

Re: When it is important to write Selenium Code

softwaretestingforum
Administrator
It would have got set up when you did -> Run as - Run Configurations in Eclipse.
Can you see what is available in run configuration for you.

Also can you paste content of that xml file which I mentioned?
~ seleniumtests.com
Reply | Threaded
Open this post in threaded view
|

Re: When it is important to write Selenium Code

Adrien007
HERE ARE THE CONTENTS OF XML:-

  <?xml version="1.0" encoding="UTF-8" ?>
  <!DOCTYPE suite (View Source for full doctype...)> 
- <suite name="Default suite" junit="false" parallel="false" configfailurepolicy="skip" thread-count="5" skipfailedinvocationcounts="false" data-provider-thread-count="10" group-by-instances="false" preserve-order="true">
- <test verbose="2" name="Default test" junit="false" skipfailedinvocationcounts="false" preserve-order="true" group-by-instances="false">
- <classes>
  <class name="com.example.tests.CrossBrowser" /> 
  </classes>
  </test>
-  
  </suite>
-  




-After deleting xml file from below path, that folder is empty but still it shows  this path in console:
C:\Users\pushpraj.singh\AppData\Local\Temp\testng-eclipse--489922267\testng-customsuite.xml 
Reply | Threaded
Open this post in threaded view
|

Re: When it is important to write Selenium Code

softwaretestingforum
Administrator
Does not look any thing wrong with it.
I noticed one more error message fro your previous message -

FAILED CONFIGURATION: @BeforeClass setUp
java.lang.NoClassDefFoundError: com/google/common/base/Function

Which all jar files are you using? Can you paste screen shot of it from your eclipse. You would find list of jars under you "Reference Library" folder in your package structure.
You need to use selenium server standalone jar which is about 20mb in size.
~ seleniumtests.com
Reply | Threaded
Open this post in threaded view
|

Re: When it is important to write Selenium Code

Adrien007
Ha ha ha ha...Ohh my god I am so happy, I am gonna mad...
I just added that "selenium server standalone jar" file, it ran down successfully...
I wasn't expecting that after all day such a small thing would turn up...
But hats off to you man...
You are great...
\m/     You rock...
Reply | Threaded
Open this post in threaded view
|

Re: When it is important to write Selenium Code

softwaretestingforum
Administrator
Glad it helped.
I think I should have noticed it already but I was late.
keep learning Selenium and do share you findings with us
~ seleniumtests.com
Reply | Threaded
Open this post in threaded view
|

Re: When it is important to write Selenium Code

Adrien007
I hope more n more viewers of this forum should see this specially beginners.
One more thing just renaming from firefox to iexplore isn't working here.
-how to invoke iexplore ?
-In 'IMDB' example it also invokes RC server but we dont, so whats teh significance of invoking RC server, are we lacking if we dont do that?
Reply | Threaded
Open this post in threaded view
|

Re: When it is important to write Selenium Code

softwaretestingforum
Administrator
Amen,

Pushpraj Singh wrote
One more thing just renaming from firefox to iexplore isn't working here.
-how to invoke iexplore ?
-In 'IMDB' example it also invokes RC server but we dont, so whats teh significance of invoking RC server, are we lacking if we dont do that?
Could you post that as a new question? This question thread is overgrowing :)
~ seleniumtests.com
12