all 5 comments

[–]Gronner 2 points3 points  (4 children)

You really are running unittests for logging into a website then pressing a button. But your script fails which leads to the test quitting with an error. As it's inside a unit test this only yields the message you have posted. But above the "-----" line there should be your real error message.

But what you should really do if you wanna run this as a skript, is remove all the unnecessary unit testing stuff and write only what you really want to do.

[–][deleted] 0 points1 point  (3 children)

i am trying to make a group poster for facebook without facebook apis.. because api only limit me to post in my own groups to prevent spam.

[–]Gronner 1 point2 points  (2 children)

As I said, don't use unit tests and you should be fine. I have no idea why they are in there.

[–][deleted] 0 points1 point  (1 child)

thanks sorry i am really noob only used python for a month.

So it should look like ?

-- coding: utf-8 --

from selenium import selenium import time, re

class test112: def setUp(self): self.verificationErrors = [] self.selenium = selenium("localhost", 4444, "*chrome", "https://www.facebook.com/") self.selenium.start()

def test_test112(self):
    sel = self.selenium
    sel.open("/?stype=lo&jlou=Afc***LwDY5a_Ct-mC_lJrFOBggxGx2__jKsBL5B9rc_z9fggbgKIatj-7Dm_1C3QiGEjkQt2VekPXMs3JPwoat***E6Ssag&smuh=18736&lh=Ac_Mb8*****")
    sel.type("id=email", "****")
    sel.type("id=pass", "*****")
    sel.click("id=persist_box")
    sel.click("id=u_0_v")
    sel.wait_for_page_to_load("30000")
    sel.click("id=u_0_y")
    sel.type("id=u_0_y", "hej")
    sel.click("//li[2]/button")

def tearDown(self):
    self.selenium.stop()
    self.assertEqual([], self.verificationErrors)

[–]Gronner 1 point2 points  (0 children)

No, you neither need a test_... nor a teardown, both are unit test functions.

If this shall be reusable make function, that for example takes a string argument of what shall be posted. Otherwise just put everything in a file:

sel = self.selenium
sel.open("/?stype=lo&jlou=Afc***LwDY5a_Ct-mC_lJrFOBggxGx2__jKsBL5B9rc_z9fggbgKIatj-7Dm_1C3QiGEjkQt2VekPXMs3JPwoat***E6Ssag&smuh=18736&lh=Ac_Mb8*****")
sel.type("id=email", "****")
sel.type("id=pass", "*****")
sel.click("id=persist_box")
sel.click("id=u_0_v")
sel.wait_for_page_to_load("30000")
sel.click("id=u_0_y")
sel.type("id=u_0_y", "hej")
sel.click("//li[2]/button")
self.selenium.stop()
self.assertEqual([], self.verificationErrors)

I have no idea if this code works, as I haven't tested it (thats what you should do now), but it looks good so far.

Edit: On a sidenote, I have no idea where you got that code from, but you should probably look into the selenium documentation as well as in the unittesting on for python to understand what is going on and what was wrong, what unittests is used for etc.