开发者

Selenium tests not getting executed on Eclipse

开发者 https://www.devze.com 2023-04-10 22:17 出处:网络
I am trying to login to our company product site via selenium.I am able to do it via the Selenium IDE. And this is the code that the IDE exports usi开发者_开发百科ng JUnit4(Remote Control):

I am trying to login to our company product site via selenium.I am able to do it via the Selenium IDE. And this is the code that the IDE exports usi开发者_开发百科ng JUnit4(Remote Control):

package com.beginning;

import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.regex.Pattern;

public class testcase extends SeleneseTestCase {
    @Before
    public void setUp() throws Exception {
        selenium = new DefaultSelenium("localhost", 4444, "*chrome", "link");
        selenium.start();
    }

    @Test
    public void testTestcase() throws Exception {
        selenium.open("complete link");
        selenium.type("name=j_username", "username");
        selenium.type("name=j_password", "password");
        selenium.click("css=input[type=\"submit\"]");
        selenium.waitForPageToLoad("30000");
        //selenium.click("link=Sign out");
        //selenium.waitForPageToLoad("30000");
    }

    @After
    public void tearDown() throws Exception {
        selenium.stop();
    }
}

My doubts are :

1.Why does selenium IDE export the browser type as *chrome when I am actually doing it in firefox. 2.If I use the test as it is, it enters the values and then gives an exception . 3.If I change the browser Type to *firefox, it starts execution but nothing happens at all. Basically hangs.

Things work fine when doing it from the IDE.

Thanks.


Change your "link" (4th parameter of DefaultSelenium constructor) so it's actually a valid URL (the site you want to target)


Would reccommend you to check the version of firefox and upgrade to latest.I have used a similar scenario. Pls find the code below. You can use this its works grt.Hope you find it useful.

import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;


public class TestRun {
public static void main(String[] args)
{
Selenium selenium=new DefaultSelenium("localhost", 4444 , "*firefox","myurl");
selenium.start();
selenium.open("myurl");
System.out.println("Open browser "+selenium);
selenium.windowMaximize();
selenium.type("id=j_username","Lal");
selenium.type("name=j_password","lal");
selenium.click("name=submit");
**selenium.waitForPageToLoad("60000");**
if(selenium.isTextPresent("Lal"))
{
    selenium.click("id=common_header_logout");
}
else
{
    System.out.println("User not found");
}
}
}
0

精彩评论

暂无评论...
验证码 换一张
取 消